package com.tjtt.tdm.form.action;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.URLEncoder;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.apache.struts2.ServletActionContext;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.opensymphony.xwork2.ActionContext;
import com.tjtt.common.utils.DateUtilsAll;
import com.tjtt.common.utils.StringUtil;
import com.tjtt.tdm.base.BaseAction;
import com.tjtt.tdm.base.GenerateSequenceUtil;
import com.tjtt.tdm.base.PageResult;
import com.tjtt.tdm.base.PubMethod;
import com.tjtt.tdm.form.bean.TdmAnnex;
import com.tjtt.tdm.flow.bean.TdmCustomNo;
import com.tjtt.tdm.form.bean.AutoFormsField;
import com.tjtt.tdm.form.bean.AutoFormsNew;
import com.tjtt.tdm.form.bean.ReportParameter;
import com.tjtt.tdm.form.service.IAutoFormService;
import com.tjtt.tdm.form.service.IAutoService;
import com.tjtt.tdm.util.WordTool;

public class AutoAction extends BaseAction{

	private String media;
	private IAutoService autoService;
	private IAutoFormService autoFormService;
	public static final int MOD_CHECK = 3;//每行显示几个复选框
	private TdmCustomNo tdmCustomNo ;
	private List uploadfile;
	private List uploadfileContentType;
	private List uploadfileFileName;
	WebApplicationContext factory = WebApplicationContextUtils.getRequiredWebApplicationContext(ServletActionContext.getServletContext());  
	public IAutoFormService getAutoFormService() {
		return autoFormService;
	}
	public void setAutoFormService(IAutoFormService autoFormService) {
		this.autoFormService = autoFormService;
	}
	public IAutoService getAutoService() {
		return autoService;
	}
	public void setAutoService(IAutoService autoService) {
		this.autoService = autoService;
	}
	/**
	 * 跳转页面前查询信息(表单专用)
	 * author:lishu	 2013-10-25
	 */
	public String gotoList(){
		try {
			/****绑定按钮关联查询需要用的参数  START *****/
			
			String byTableColumn = getRequest().getParameter("byTableColumn");//外键名称
			String byTableValue = getRequest().getParameter("byTableValue");//外键值
			String mobanid = getRequest().getParameter("mobanid");//外键值
			/****绑定按钮关联查询需要用的参数  END *****/
			String formId = getRequest().getParameter("formid");
			String sbtype = getRequest().getParameter("sbtype");
			String flag = getRequest().getParameter("flag");//技术条件模板流程审核查看信息标记
			String menuName = getRequest().getParameter("menuname");
			String strIsChild=getRequest().getParameter("isChild");
			String isreport = getRequest().getParameter("isreport");
			if (isreport==null){
				isreport = "";
			}
			if(null!=menuName&&!"".equals(menuName)){
				menuName = StringUtil.encodingUrl(menuName);
			}
			
			//查询表单信息
			AutoFormsNew formnew =  autoFormService.getAutoFormsNewById(formId);
			String formWidth = "500";
			String formHeight = "500";
			
			String columnguolvsql = "";
			if( formnew.getFormwidth() != null && !"".equals(formnew.getFormwidth())){
				formWidth = formnew.getFormwidth();
			}
			if( formnew.getFormheight() != null && !"".equals(formnew.getFormheight())){
				formHeight = formnew.getFormheight();
			}
			if(  !"".equals(formnew.getColumnguolvsql())){
				columnguolvsql = formnew.getColumnguolvsql();
			}
			String formIdChild = null;
			String fieldChild = null;
			String fieldParent = null;
			List<AutoFormsField> formListChild=new ArrayList();
			//查询子表ID
			String sql = "select t.by_table_name_id,by_table_column,this_table_column from auto_forms_button t where t.this_table_name_id = "+formId +" and t.button_type = 0 ";
			List<Object[]> list = autoService.getDatabySql(sql);
			if(list.size()>0)
			{
				Object[] objChild=list.get(0);
				formIdChild=objChild[0].toString(); //子表ID
				fieldChild=objChild[1].toString();  //子表关联字段
				fieldParent=objChild[2].toString();	//父表关联字段				
				formListChild=autoFormService.getAutoFormsFieldByformid(formIdChild);
				//查询子表名称
				sql="select t.form_en_name from auto_forms_new t where t.id='";
				sql+=formIdChild;
				sql+="'";
				List<String> listTableName=autoService.getDatabySql(sql);
				formIdChild=listTableName.get(0).toString();
			}
			String colName = "";
			String colModel = "";
			String columns = "";
			String queryColumns = "";
			String queryColumnsChild = "";
			String isOrderBy = "";
			StringBuffer sb = new StringBuffer();
			StringBuffer qb = new StringBuffer();
			StringBuffer sbreset = new StringBuffer();
			//String type = "";
			//查询字段信息
			List<AutoFormsField> formList = autoFormService.getAutoFormsFieldByformid(formId);			
			//是否有查询条件
			int hasQuery = 0;
			sb.append("<td><table  border='0' cellpadding='6' cellspacing='0' class='tabman' style='margin-bottom:0px'><tr>");
			int column = 0;//記錄是多少列的數據
			for (int i = 0; i < formList.size(); i++) {
				AutoFormsField form = formList.get(i);
				if(!"ID".equals(form.getFieldName())){
					//type =  form.getPageDisplayType().toString();
				}
				if("1".equals(String.valueOf(form.getIsOrderBy()))){//是否排序（0：否，1：是）
					isOrderBy += ""+ form.getFieldName() +" desc ,";
				}
				if("1".equals(String.valueOf(form.getIsListShow()))){//如果是列表显示  
					colName += "'"+ form.getCnName() +"',";
					int width = 100;
					if(form.getFieldListWidth()!=null){
						width = form.getFieldListWidth().intValue();
					}
					if("ID".equals(form.getFieldName())){
						colModel += "{name:'"+form.getFieldName()+"',index:'"+form.getFieldName()+"',key:true,hidden:true, width:"+width+",hidedlg:true},";
					}else{
						colModel += "{name:'"+form.getFieldName()+"',index:'"+form.getFieldName()+"', width:"+width+"},";
					}
					columns += form.getFieldName() + ",";
				}else{
					colName += "'"+ form.getCnName() +"',";
					int width = 100;
					if(form.getFieldListWidth()!=null){
						width = form.getFieldListWidth().intValue();
					}
					if("ID".equals(form.getFieldName())){
						colModel += "{name:'"+form.getFieldName()+"',index:'"+form.getFieldName()+"',key:true, width:"+width+",hidden:true,hidedlg:true},";
					}else{
						colModel += "{name:'"+form.getFieldName()+"',index:'"+form.getFieldName()+"', width:"+width+",hidden:true,hidedlg:true},";
					}
					columns += form.getFieldName() + ",";
				}
				if("1".equals(String.valueOf(form.getIsQueryField()))){//如果是查询条件
					hasQuery = 1;
					String type = String.valueOf(form.getPageDisplayType());
					if (column %4 == 0) {
						  sb.append("</tr><tr>");
					}
					column++;
					if("1".equals(type)){//时间空间
						qb.append("\""+form.getFieldName()+"\":encodeURIComponent(jQuery('#"+form.getFieldName()+"').val()),");
						queryColumns += form.getFieldName()+",";
						sb.append("<td>"+form.getCnName()+"：</td><td><input type=\"text\" id=\""+form.getFieldName()+"\" onClick=\"WdatePicker()\" name=\""+form.getFieldName()+"\" value=\"\"  /></td>");
						
					}else if("2".equals(type)){//下拉菜单
						String defaultValue =form.getDefaultValue();
						if(!StringUtil.isEmpty(defaultValue)){
							String[] values = defaultValue.split(",");
							qb.append("\""+form.getFieldName()+"\":encodeURIComponent($('#"+form.getFieldName()+"').combobox('getValues')),");
							queryColumns += form.getFieldName()+",";

							String datas = "[";
							for(String value : values){
								datas += "{label: '"+value+"',value: '"+value+"'},";
							}
							if (datas.length()>0){
								datas = datas.substring(0, datas.length()-1);
							}
							datas+="]";
							
						    sb.append("<td>"+form.getCnName()+"：</td>");
							sb.append("<td><input class=\"easyui-combobox\" id=\""+form.getFieldName()+"\" name=\""+form.getFieldName()+"\" data-options=\"valueField:'value',textField:'label',multiple:true,panelHeight:'auto',data:"+datas+"\">");
							sb.append("</td>");
							sbreset.append("$('#"+form.getFieldName()+"').combobox('setValues','');");
						}
					}else if("8".equals(type)){//操作时间
						qb.append("\""+form.getFieldName()+"\":encodeURIComponent(jQuery('#"+form.getFieldName()+"').val()),");
						queryColumns += form.getFieldName()+",";
						sb.append("<td>"+form.getCnName()+"：</td><td><input type=\"text\" readonly=readonly id=\""+form.getFieldName()+"\" onClick=\"WdatePicker()\" name=\""+form.getFieldName()+"\" value=\"\" class=\"tab_input\"/></td>");
						
					}else if("9".equals(type)){//操作日期
						qb.append("\""+form.getFieldName()+"\":encodeURIComponent(jQuery('#"+form.getFieldName()+"').val()),");
						queryColumns += form.getFieldName()+",";
						sb.append("<td>"+form.getCnName()+"：</td><td><input type=\"text\" readonly=readonly id=\""+form.getFieldName()+"\" onClick=\"WdatePicker()\" name=\""+form.getFieldName()+"\" value=\"\" class=\"tab_input\"/></td>");
						
					}else if("10".equals(type)){//选择部门
						qb.append("\""+form.getFieldName()+"\":encodeURIComponent(jQuery('#"+form.getFieldName()+"').val()),");
						queryColumns += form.getFieldName()+",";
						sb.append("<td>"+"<input type=\"hidden\" id=\""+form.getFieldName()+"\" name=\""+form.getFieldName()+"\">");
						sb.append(form.getCnName()+"：</td><td><input type=\"text\" readonly=readonly id=\"dept_"+form.getFieldName()+"\" name=\"dept_"+form.getFieldName()+"\" value=\"\" />");
						sb.append("<img src=\"web/images/form_icon_1.gif\" style=\"cursor:hand; vertical-align: middle;\" onclick=\"selectdept('"+form.getFieldName()+"')\" /></td>");
					}
					else if(!StringUtil.isEmpty(form.getForeignTableName())){//如果不满足上述条件  则判断外键是否存在
						qb.append("\""+form.getFieldName()+"\":encodeURIComponent(jQuery('#"+form.getFieldName()+"').val()),");
						queryColumns += form.getFieldName()+",";
						//sb.append("<td>"+"<input type=\"hidden\" id=\""+form.getFieldName()+"\" name=\""+form.getFieldName()+"\">");
						sb.append("<td>"+"<input type=\"hidden\" id=\"test"+form.getFieldName()+"\" name=\""+form.getFieldName()+"\" value=\"\"  >" );
						
						//sb.append(form.getCnName()+"：</td><td><input type=\"text\" readonly=readonly id=\"data_"+form.getFieldName()+"\" name=\"data_"+form.getFieldName()+"\" value=\"\" class=\"tab_input\" style='width:130px;' />");
						sb.append(form.getCnName()+"：</td><td><input type=\"text\" readonly=readonly id=\""+form.getFieldName()+"\" name=\"data_"+form.getFieldName()+"\" value=\"\" class=\"tab_input\" style='width:130px;' />");
						
						//sb.append(form.getCnName()+"：</td><td><input type=\"text\"  class=\"input\"  style=\"width:150px;\" readonly=readonly id=\""+form.getFieldName()+"\" name=\""+form.getFieldName()+"\" value=\"\" />");
						
						sb.append("<img src=\"web/images/form_icon_1.gif\" style=\"cursor:hand; vertical-align: middle;\" onclick=\"selectData('"+form.getFieldName()+"','"+form.getForeignTableName()+"','"+form.getForeignCloumn()+"','"+form.getForeignDisCloumn()+"','"+form.getCnName()+"','"+form.getDefaultValue()+"','"+getRequest().getParameter("formid")+"')\" /></td>");
					}
					else{
						qb.append("\""+form.getFieldName()+"\":encodeURIComponent(jQuery('#"+form.getFieldName()+"').val()),");
						queryColumns += form.getFieldName()+",";
						sb.append("<td>"+form.getCnName()+"：</td><td><input type=\"text\" class=\"input\" style=\"width:150px;\" id=\""+form.getFieldName()+"\" name=\""+form.getFieldName()+"\" value=\"\" /></td>");
					}
				}
			}
			for (int i = 0; i < formListChild.size(); i++) {
				AutoFormsField form = formListChild.get(i);
				
				if("1".equals(String.valueOf(form.getIsQueryField()))){//如果是查询条件
					hasQuery = 1;
					String type = String.valueOf(form.getPageDisplayType());
					if (column %4 == 0) {
						  sb.append("</tr><tr>");
					}
					column++;
					if("1".equals(type)){//时间空间
						qb.append("\""+form.getFieldName()+"\":encodeURIComponent(jQuery('#"+form.getFieldName()+"').val()),");
						queryColumnsChild += form.getFieldName()+",";
						sb.append("<td>"+form.getCnName()+"：</td><td><input type=\"text\" id=\""+form.getFieldName()+"\" onClick=\"WdatePicker()\" name=\""+form.getFieldName()+"\" value=\"\"  /></td>");
						
					}else if("2".equals(type)){//下拉菜单
						String defaultValue =form.getDefaultValue();
						if(!StringUtil.isEmpty(defaultValue)){
							String[] values = defaultValue.split(",");
							qb.append("\""+form.getFieldName()+"\":encodeURIComponent($('#"+form.getFieldName()+"').combobox('getValues')),");
							queryColumnsChild += form.getFieldName()+",";
//						    sb.append("<td>"+form.getCnName()+"：</td><td><select id=\""+form.getFieldName()+"\"  style=\"width:150px;\" class='fselect' name=\""+form.getFieldName()+"\" >");
//						    sb.append("<option value=\"\">----请选择----</option>");
//						    for(String value : values){
//								sb.append("<option value=\""+value+"\">"+value+"</option>");
//							}
//							sb.append("</select></td>");

							String datas = "[";
							for(String value : values){
								datas += "{label: '"+value+"',value: '"+value+"'},";
							}
							if (datas.length()>0){
								datas = datas.substring(0, datas.length()-1);
							}
							datas+="]";
							
						    sb.append("<td>"+form.getCnName()+"：</td>");
							sb.append("<td><input class=\"easyui-combobox\" id=\""+form.getFieldName()+"\" name=\""+form.getFieldName()+"\" data-options=\"valueField:'value',textField:'label',multiple:true,panelHeight:'auto',data:"+datas+"\">");
							sb.append("</td>");
							sbreset.append("$('#"+form.getFieldName()+"').combobox('setValues','');");
						}
					}else if("8".equals(type)){//操作时间
						qb.append("\""+form.getFieldName()+"\":encodeURIComponent(jQuery('#"+form.getFieldName()+"').val()),");
						queryColumnsChild += form.getFieldName()+",";
						sb.append("<td>"+form.getCnName()+"：</td><td><input type=\"text\" readonly=readonly id=\""+form.getFieldName()+"\" onClick=\"WdatePicker()\" name=\""+form.getFieldName()+"\" value=\"\" class=\"tab_input\"/></td>");
						
					}else if("9".equals(type)){//操作日期
						qb.append("\""+form.getFieldName()+"\":encodeURIComponent(jQuery('#"+form.getFieldName()+"').val()),");
						queryColumnsChild += form.getFieldName()+",";
						sb.append("<td>"+form.getCnName()+"：</td><td><input type=\"text\" readonly=readonly id=\""+form.getFieldName()+"\" onClick=\"WdatePicker()\" name=\""+form.getFieldName()+"\" value=\"\" class=\"tab_input\"/></td>");
						
					}else if("10".equals(type)){//选择部门
						qb.append("\""+form.getFieldName()+"\":encodeURIComponent(jQuery('#"+form.getFieldName()+"').val()),");
						queryColumnsChild += form.getFieldName()+",";
						sb.append("<td>"+"<input type=\"hidden\" id=\""+form.getFieldName()+"\" name=\""+form.getFieldName()+"\">");
						sb.append(form.getCnName()+"：</td><td><input type=\"text\" readonly=readonly id=\"dept_"+form.getFieldName()+"\" name=\"dept_"+form.getFieldName()+"\" value=\"\" />");
						sb.append("<img src=\"web/images/form_icon_1.gif\" style=\"cursor:hand; vertical-align: middle;\" onclick=\"selectdept('"+form.getFieldName()+"')\" /></td>");
					}
					else if(!StringUtil.isEmpty(form.getForeignTableName())){//如果不满足上述条件  则判断外键是否存在
						System.out.println("------------------");
						System.out.println(form.getFieldName());
						qb.append("\""+form.getFieldName()+"\":encodeURIComponent(jQuery('#"+form.getFieldName()+"').val()),");
						queryColumnsChild += form.getFieldName()+",";
						//sb.append("<td>"+"<input type=\"hidden\" id=\""+form.getFieldName()+"\" name=\""+form.getFieldName()+"\">");
						sb.append("<td>"+"<input type=\"hidden\" id=\""+form.getFieldName()+"\" name=\""+form.getFieldName()+"\" value=\"\">" );
						
						//sb.append(form.getCnName()+"：</td><td><input type=\"text\" readonly=readonly id=\"data_"+form.getFieldName()+"\" name=\"data_"+form.getFieldName()+"\" value=\"\" class=\"tab_input\" style='width:130px;'/>");
						sb.append(form.getCnName()+"：</td><td><input type=\"text\" readonly=readonly id=\"data_"+form.getFieldName()+"\" name=\"data_"+form.getFieldName()+"\" value=\"\" class=\"tab_input\" style='width:100px;'/>");
						
						//sb.append(form.getCnName()+"：</td><td><input type=\"text\"  class=\"input\" readonly=readonly id=\""+form.getFieldName()+"\" name=\""+form.getFieldName()+"\" value=\"\" />");
						
						sb.append("<img src=\"web/images/form_icon_1.gif\" style=\"cursor:hand; vertical-align: middle;\" onclick=\"selectData('"+form.getFieldName()+"','"+form.getForeignTableName()+"','"+form.getForeignCloumn()+"','"+form.getForeignDisCloumn()+"','"+form.getCnName()+"','"+form.getDefaultValue()+"','"+getRequest().getParameter("formid")+"')\" /></td>");
					}
					else{
						qb.append("\""+form.getFieldName()+"\":encodeURIComponent(jQuery('#"+form.getFieldName()+"').val()),");
						queryColumnsChild += form.getFieldName()+",";
						sb.append("<td>"+form.getCnName()+"：</td><td><input type=\"text\" class=\"input\" style=\"width:150px;\" id=\""+form.getFieldName()+"\" name=\""+form.getFieldName()+"\" value=\"\" /></td>");
					}
				}
			}
			sb.append("</tr>");
			//sb.append("<tr><td colspan='6' align='left'>");
			//sb.append("<input type='button' class='button_b' value='查询' onclick='gridSearch()'/><input type='button' class='button_b' value='清空' onclick='reset()'/>");
			//sb.append("</td></tr>");
			sb.append("</table></td>");
			if (hasQuery==1){
				sb.append("<td style='width:150px;padding-top:10px;' valign='top'>");
				sb.append("<input type='button' class='button_b' value='查 询' onclick='gridSearch()'/>");
				sb.append("&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp");
				//sb.append("<input type='button' class='button_b' value='清 空' onclick='reset()'/></td>");
				sb.append("<input type='button' class='button_b' value='清 空' onclick='resetsearch()'/></td>");
			}
			if(colName.length()>0){
				colName = colName.substring(0,colName.length()-1);
			}
			if(colModel.length()>0){
				colModel = colModel.substring(0,colModel.length()-1);
			}
			if(columns.length()>0){
				columns = columns.substring(0,columns.length()-1);
			}
			if(isOrderBy.length()>0){
				isOrderBy = isOrderBy.substring(0,isOrderBy.length()-1);
			}
			/******************************************生成列表中关联的按钮 类型按钮  START***********************************************/
			StringBuffer buttonSb = new StringBuffer();
			String buttonSql = "select t.button_name,t.by_table_name_id,t.by_table_column from auto_forms_button t where t.this_table_name_id = "+formId +" and t.button_type = 0 ";
			List buttonList = autoService.getDatabySql(buttonSql);
			if(buttonList != null && buttonList.size() != 0 ){
				for (int j = 0; j < buttonList.size(); j++) {
					Object[] obj = (Object[])buttonList.get(j);
					buttonSb.append("<input type=\"button\" class=\"button_b\" value=\""+obj[0]+"\" onclick=\"buttonOnclick("+obj[1]+",'"+obj[0]+"','"+obj[2]+"')\"/>\r\n");
				}
			}
			/******************************************生成列表中关联的按钮  END*************************************************/
			if(strIsChild==null)
			{
				getRequest().setAttribute("isChild", false);
			}
			else if(strIsChild.equals("true"))
			{
				getRequest().setAttribute("isChild",true );
			}
			
			getRequest().setAttribute("formIdChild", formIdChild);	//子表ID
			getRequest().setAttribute("fieldChild", fieldChild);	//子表关联字段
			getRequest().setAttribute("fieldParent", fieldParent);	//父表关联字段
			getRequest().setAttribute("queryValue", qb);
			getRequest().setAttribute("queryColumns", queryColumns);
			getRequest().setAttribute("queryColumnsChild", queryColumnsChild);
			getRequest().setAttribute("queryContent", sb);
			getRequest().setAttribute("formid", formId);
			getRequest().setAttribute("formnew", formnew);
			getRequest().setAttribute("colName", colName);
			getRequest().setAttribute("colModel", colModel);
			getRequest().setAttribute("columns", columns);
			getRequest().setAttribute("formWidth", formWidth);
			getRequest().setAttribute("formHeight", formHeight);
			getRequest().setAttribute("buttonList", buttonSb);
			getRequest().setAttribute("mobanid", mobanid);
			getRequest().setAttribute("isOrderBy", isOrderBy);
			getRequest().setAttribute("byTableColumn", byTableColumn);
			getRequest().setAttribute("byTableValue", byTableValue);
			getRequest().setAttribute("sbtype", sbtype);
			getRequest().setAttribute("flag", flag);
			getRequest().setAttribute("columnguolvsql",columnguolvsql);
			getRequest().setAttribute("menuName",menuName);
			getRequest().setAttribute("sbreset",sbreset.toString());
			getRequest().setAttribute("isreport",isreport);
			if (formnew.getIsshowmap()!=null&&formnew.getIsshowmap()==1){
				//tablename,markname
				String tablename = formnew.getFormEnName();
				String tablecnname = formnew.getFormCnName();
				getRequest().setAttribute("btnmap", "<input id='update' type='button' value='地 图' onclick='addTree(\""+tablename+"\",\""+tablecnname+"\")' class='button_b' />");
				getRequest().setAttribute("mapmark",formnew.getMapmark());
				getRequest().setAttribute("marktype",formnew.getMarktype());
				if (formnew.getBjingdu()==null){
					getRequest().setAttribute("bjingdu","temp");
					getRequest().setAttribute("bweidu","temp");
				}
				else{
					getRequest().setAttribute("bjingdu",formnew.getBjingdu());
					getRequest().setAttribute("bweidu",formnew.getBweidu());
				}
				
				if (formnew.getEjingdu()==null){
					getRequest().setAttribute("ejingdu","temp");
					getRequest().setAttribute("eweidu","temp");
				}
				else{
					getRequest().setAttribute("ejingdu",formnew.getEjingdu());
					getRequest().setAttribute("eweidu",formnew.getEweidu());
				}
			}
			else{
				getRequest().setAttribute("btnmap", "");
				getRequest().setAttribute("mapmark","temp");
				getRequest().setAttribute("bjingdu","temp");
				getRequest().setAttribute("bweidu","temp");
				getRequest().setAttribute("ejingdu","temp");
				getRequest().setAttribute("eweidu","temp");
			}
			
			return "viewlist";
		} catch (Exception e) {
			e.printStackTrace();
			return "error";
		}
	}
	
	public String gotoListQuery(){
		try {
			/****绑定按钮关联查询需要用的参数  START *****/
			String byTableColumn = getRequest().getParameter("byTableColumn");//外键名称
			String byTableValue = getRequest().getParameter("byTableValue");//外键值
			String mobanid = getRequest().getParameter("mobanid");//外键值
			/****绑定按钮关联查询需要用的参数  END *****/
			String formId = getRequest().getParameter("formid");
			String sbtype = getRequest().getParameter("sbtype");
			String flag = getRequest().getParameter("flag");//技术条件模板流程审核查看信息标记
			String menuName = getRequest().getParameter("menuname");
			String strIsChild=getRequest().getParameter("isChild");
			String pipelineno=getRequest().getParameter("pipelineno");
			String pipenetno=getRequest().getParameter("pipenetno");
			String pipesectionnos=getRequest().getParameter("pipesectionnos");
			String tasknos=getRequest().getParameter("tasknos");
			String owner=getRequest().getParameter("owner");
			if(owner!=null&&owner.equals("pipeSectionSearch"))
			{
				if (pipesectionnos==null){
					Object obj=getSession().getAttribute("pipesectionnos");
					if(obj!=null)
					{
						pipesectionnos=obj.toString();
					}
				}
			}
			if(owner!=null&&owner.equals("TaskSearch"))
			{
				if (tasknos==null){
					Object obj=getSession().getAttribute("tasknos");
					if(obj!=null)
					{
						tasknos =obj.toString();
					}					
				}
			}
			
			
//			System.out.print("----------------------");
//			System.out.print(pipesectionnos);
			String type=getRequest().getParameter("type");
			if(type==null)
			{
				type="";
			}
			if(null!=menuName&&!"".equals(menuName)){
				menuName = StringUtil.encodingUrl(menuName);
			}
			
			//查询表单信息
			AutoFormsNew formnew =  autoFormService.getAutoFormsNewById(formId);
			String formWidth = "500";
			String formHeight = "500";
			String columnguolvsql = "";
			if( formnew.getFormwidth() != null && !"".equals(formnew.getFormwidth())){
				formWidth = formnew.getFormwidth();
			}
			if( formnew.getFormheight() != null && !"".equals(formnew.getFormheight())){
				formHeight = formnew.getFormheight();
			}
			if(  !"".equals(formnew.getColumnguolvsql())){
				columnguolvsql = formnew.getColumnguolvsql();
			}
			//查询字段信息
			List<AutoFormsField> formList = autoFormService.getAutoFormsFieldByformid(formId);
			String colName = "";
			String colModel = "";
			String columns = "";
			String queryColumns = "";
			String isOrderBy = "";
			StringBuffer sb = new StringBuffer();
			StringBuffer qb = new StringBuffer();
			//String type = "";
			//是否有查询条件
			int hasQuery = 0;
			sb.append("<td><table  border='0' cellpadding='6' cellspacing='0' class='tabman' style='margin-bottom:0px'><tr>");
			int column = 0;//記錄是多少列的數據
			for (int i = 0; i < formList.size(); i++) {
				AutoFormsField form = formList.get(i);
				if(!"ID".equals(form.getFieldName())){
					//type =  form.getPageDisplayType().toString();
				}
				if("1".equals(String.valueOf(form.getIsOrderBy()))){//是否排序（0：否，1：是）
					isOrderBy += ""+ form.getFieldName() +" desc ,";
				}
				if("1".equals(String.valueOf(form.getIsListShow()))){//如果是列表显示  
					colName += "'"+ form.getCnName() +"',";
					int width = 100;
					if(form.getFieldListWidth()!=null){
						width = form.getFieldListWidth().intValue();
					}
					if("ID".equals(form.getFieldName())){
						colModel += "{name:'"+form.getFieldName()+"',index:'"+form.getFieldName()+"',key:true,hidden:true, width:"+width+",hidedlg:true},";
					}else{
						colModel += "{name:'"+form.getFieldName()+"',index:'"+form.getFieldName()+"', width:"+width+"},";
					}
					columns += form.getFieldName() + ",";
				}else{
					colName += "'"+ form.getCnName() +"',";
					int width = 100;
					if(form.getFieldListWidth()!=null){
						width = form.getFieldListWidth().intValue();
					}
					if("ID".equals(form.getFieldName())){
						colModel += "{name:'"+form.getFieldName()+"',index:'"+form.getFieldName()+"',key:true, width:"+width+",hidden:true,hidedlg:true},";
					}else{
						colModel += "{name:'"+form.getFieldName()+"',index:'"+form.getFieldName()+"', width:"+width+",hidden:true,hidedlg:true},";
					}
					columns += form.getFieldName() + ",";
				}
			}
			sb.append("</tr>");
			//sb.append("<tr><td colspan='6' align='left'>");
			//sb.append("<input type='button' class='button_b' value='查询' onclick='gridSearch()'/><input type='button' class='button_b' value='清空' onclick='reset()'/>");
			//sb.append("</td></tr>");
			sb.append("</table></td>");
			if(colName.length()>0){
				colName = colName.substring(0,colName.length()-1);
			}
			if(colModel.length()>0){
				colModel = colModel.substring(0,colModel.length()-1);
			}
			if(columns.length()>0){
				columns = columns.substring(0,columns.length()-1);
			}
			if(isOrderBy.length()>0){
				isOrderBy = isOrderBy.substring(0,isOrderBy.length()-1);
			}
			/******************************************生成列表中关联的按钮 类型按钮  START***********************************************/
			StringBuffer buttonSb = new StringBuffer();
			String buttonSql = "select t.button_name,t.by_table_name_id,t.by_table_column from auto_forms_button t where t.this_table_name_id = "+formId +" and t.button_type = 0 ";
			List buttonList = autoService.getDatabySql(buttonSql);
			if(buttonList != null && buttonList.size() != 0 ){
				for (int j = 0; j < buttonList.size(); j++) {
					Object[] obj = (Object[])buttonList.get(j);
					buttonSb.append("<input type=\"button\" class=\"button_b\" value=\""+obj[0]+"\" onclick=\"buttonOnclick("+obj[1]+",'"+obj[0]+"','"+obj[2]+"')\"/>\r\n");
				}
			}
			/******************************************生成列表中关联的按钮  END*************************************************/
			if(strIsChild==null)
			{
				getRequest().setAttribute("isChild", false);
			}
			else if(strIsChild.equals("true"))
			{
				getRequest().setAttribute("isChild",true );
			}
			if(type.equals("xljcxld"))
			{
				getRequest().setAttribute("isXljc", true);
			}
			else
			{
				getRequest().setAttribute("isXljc", false);
			}
			if(pipesectionnos!=null)
			{
				getRequest().setAttribute("pipesectionnos", pipesectionnos);
			}
			if(tasknos!=null)
			{
				getRequest().setAttribute("tasknos", tasknos);
			}
			if(pipelineno!=null)
			{
				getRequest().setAttribute("pipelineno", pipelineno);
			}
			if(pipenetno!=null)
			{
				getRequest().setAttribute("pipenetno", pipenetno);
			}
			if(owner!=null)
			{
				getRequest().setAttribute("owner", owner);
			}
			getRequest().setAttribute("queryValue", qb);
			getRequest().setAttribute("queryColumns", queryColumns);
			getRequest().setAttribute("queryContent", sb);
			getRequest().setAttribute("formid", formId);
			getRequest().setAttribute("formnew", formnew);
			getRequest().setAttribute("colName", colName);
			getRequest().setAttribute("colModel", colModel);
			getRequest().setAttribute("columns", columns);
			getRequest().setAttribute("formWidth", formWidth);
			getRequest().setAttribute("formHeight", formHeight);
			getRequest().setAttribute("buttonList", buttonSb);
			getRequest().setAttribute("mobanid", mobanid);
			getRequest().setAttribute("isOrderBy", isOrderBy);
			getRequest().setAttribute("byTableColumn", byTableColumn);
			getRequest().setAttribute("byTableValue", byTableValue);
			getRequest().setAttribute("sbtype", sbtype);
			getRequest().setAttribute("flag", flag);
			getRequest().setAttribute("columnguolvsql",columnguolvsql);
			getRequest().setAttribute("menuName",menuName);
			if (formnew.getIsshowmap()!=null&&formnew.getIsshowmap()==1){
				//tablename,markname
				String tablename = formnew.getFormEnName();
				String tablecnname = formnew.getFormCnName();
				getRequest().setAttribute("btnmap", "<input id='update' type='button' value='地 图' onclick='addTree(\""+tablename+"\",\""+tablecnname+"\")' class='button_b' />");
				getRequest().setAttribute("mapmark",formnew.getMapmark());
				getRequest().setAttribute("marktype",formnew.getMarktype());
				if (formnew.getBjingdu()==null){
					getRequest().setAttribute("bjingdu","temp");
					getRequest().setAttribute("bweidu","temp");
				}
				else{
					getRequest().setAttribute("bjingdu",formnew.getBjingdu());
					getRequest().setAttribute("bweidu",formnew.getBweidu());
				}
				
				if (formnew.getEjingdu()==null){
					getRequest().setAttribute("ejingdu","temp");
					getRequest().setAttribute("eweidu","temp");
				}
				else{
					getRequest().setAttribute("ejingdu",formnew.getEjingdu());
					getRequest().setAttribute("eweidu",formnew.getEweidu());
				}
			}
			else{
				getRequest().setAttribute("btnmap", "");
				getRequest().setAttribute("mapmark","temp");
				getRequest().setAttribute("bjingdu","temp");
				getRequest().setAttribute("bweidu","temp");
				getRequest().setAttribute("ejingdu","temp");
				getRequest().setAttribute("eweidu","temp");
			}
			return "viewlistQuery";
		} catch (Exception e) {
			e.printStackTrace();
			return "error";
		}
	}
	
	public void getFilemodeinfo(){
		PrintWriter out = PubMethod.GetPrintWriter();
		try {
			String filemodeid = getRequest().getParameter("filemodeid");
			String strSql = "select baseinfoid,datainfoid from file_mode where id="+filemodeid;
			List lists = autoService.getDatabySql(strSql);
			Object[] objs = (Object[])lists.get(0);
			String baseinfoid = objs[0].toString();
			String datainfoid = objs[1].toString();
			out.print("{\"result\":\"success\",\"baseinfoid\":\""+baseinfoid+"\",\"datainfoid\":\""+datainfoid+"\"}");
		}catch (Exception e) {
			e.printStackTrace();
			out.print("{\"result\":\"false\"}");
		}
	}
	
	public String gotoListForAnalysis(){
		try {
			/****绑定按钮关联查询需要用的参数  START *****/
			String byTableColumn = getRequest().getParameter("byTableColumn");//外键名称
			String byTableValue = getRequest().getParameter("byTableValue");//外键值
			String mobanid = getRequest().getParameter("mobanid");//外键值
			/****绑定按钮关联查询需要用的参数  END *****/
			String formId = getRequest().getParameter("formid");
			String filemodeid = getRequest().getParameter("filemodeid");
			String sbtype = getRequest().getParameter("sbtype");
			String flag = getRequest().getParameter("flag");//技术条件模板流程审核查看信息标记
			String menuName = getRequest().getParameter("menuname");
			
			if(null!=menuName&&!"".equals(menuName)){
				menuName = StringUtil.encodingUrl(menuName);
			}
			
			//查询表单信息
			AutoFormsNew formnew =  autoFormService.getAutoFormsNewById(formId);
			String formWidth = "500";
			String formHeight = "500";
			String columnguolvsql = "";
			if( formnew.getFormwidth() != null && !"".equals(formnew.getFormwidth())){
				formWidth = formnew.getFormwidth();
			}
			if( formnew.getFormheight() != null && !"".equals(formnew.getFormheight())){
				formHeight = formnew.getFormheight();
			}
			if(  !"".equals(formnew.getColumnguolvsql())){
				columnguolvsql = formnew.getColumnguolvsql();
			}
			//查询字段信息
			List<AutoFormsField> formList = autoFormService.getAutoFormsFieldByformid(formId);
			String colName = "";
			String colModel = "";
			String columns = "";
			String queryColumns = "";
			String isOrderBy = "";
			StringBuffer sb = new StringBuffer();
			StringBuffer qb = new StringBuffer();
			StringBuffer paras = new StringBuffer();
			//String type = "";
			sb.append("<table  border='0' cellpadding='6' cellspacing='0' class='tabman' style='margin-bottom:0px'><tr>");
			int column = 1;//記錄是多少列的數據
			
			colName = "'主键','任务ID','模板ID','任务编号','试验类型','阶段类型','试验开始时间'";
			columns = "ID,flowtaskid,filemodeid,renwubh,shiyanlx,jieduanlx,shiyankssj";
			colModel = "{name:'ID',index:'ID',key:true,hidden:true, width:100,hidedlg:true}," +
					"{name:'flowtaskid',index:'flowtaskid', width:100}," +
					"{name:'filemodeid',index:'filemodeid', width:100}," +
					"{name:'renwubh',index:'renwubh', width:100}," +
					"{name:'shiyanlx',index:'shiyanlx', width:100}," +
					"{name:'jieduanlx',index:'jieduanlx', width:100}," +
					"{name:'shiyankssj',index:'shiyankssj', width:100}";
			
			for (int i = 0; i < formList.size(); i++) {
				AutoFormsField form = formList.get(i);
				if (form.getFieldName().equals("ID")||form.getFieldName().equals("FLOWTASKID")||form.getFieldName().equals("FILEMODEID")){
					continue;
				}

				if("1".equals(String.valueOf(form.getIsOrderBy()))){//是否排序（0：否，1：是）
					isOrderBy += ""+ form.getFieldName() +" desc ,";
				}
				if("1".equals(String.valueOf(form.getIsListShow()))){//如果是列表显示  
					colName += ",'"+ form.getCnName() +"'";
					int width = 100;
					if(form.getFieldListWidth()!=null){
						width = form.getFieldListWidth().intValue();
					}
					colModel += ",{name:'"+form.getFieldName()+"',index:'"+form.getFieldName()+"', width:"+width+"}";
					columns += ","+form.getFieldName();
				}else{
					colName += ",'"+ form.getCnName() +"'";
					int width = 100;
					if(form.getFieldListWidth()!=null){
						width = form.getFieldListWidth().intValue();
					}
					colModel += ",{name:'"+form.getFieldName()+"',index:'"+form.getFieldName()+"', width:"+width+",hidden:true,hidedlg:true}";
					columns += ","+form.getFieldName();
				}
				if("1".equals(String.valueOf(form.getIsQueryField()))){//如果是查询条件
					String type = String.valueOf(form.getPageDisplayType());
					if (column %4 == 0) {
						  sb.append("</tr><tr>");
					}
					column++;
					if("1".equals(type)){//时间空间
						qb.append("\""+form.getFieldName()+"\":encodeURIComponent(jQuery('#"+form.getFieldName()+"').val()),");
						queryColumns += form.getFieldName()+",";
						sb.append("<td>"+form.getCnName()+"：</td><td><input type=\"text\" id=\""+form.getFieldName()+"\" onClick=\"WdatePicker()\" name=\""+form.getFieldName()+"\" value=\"\"  /></td>");
						
					}else if("2".equals(type)){//下拉菜单
						String defaultValue =form.getDefaultValue();
						if(!StringUtil.isEmpty(defaultValue)){
							String[] values = defaultValue.split(",");
							qb.append("\""+form.getFieldName()+"\":encodeURIComponent(jQuery('#"+form.getFieldName()+"').val()),");
							queryColumns += form.getFieldName()+",";
						    sb.append("<td>"+form.getCnName()+"：</td><td><select id=\""+form.getFieldName()+"\"  style=\"width:150px;\" class='fselect' name=\""+form.getFieldName()+"\" >");
						    sb.append("<option value=\"\">----请选择----</option>");
						    for(String value : values){
								sb.append("<option value=\""+value+"\">"+value+"</option>");
							}
							sb.append("</select></td>");
						}
					}else if("8".equals(type)){//操作时间
						qb.append("\""+form.getFieldName()+"\":encodeURIComponent(jQuery('#"+form.getFieldName()+"').val()),");
						queryColumns += form.getFieldName()+",";
						sb.append("<td>"+form.getCnName()+"：</td><td><input type=\"text\" readonly=readonly id=\""+form.getFieldName()+"\" onClick=\"WdatePicker()\" name=\""+form.getFieldName()+"\" value=\"\" class=\"tab_input\"/></td>");
						
					}else if("9".equals(type)){//操作日期
						qb.append("\""+form.getFieldName()+"\":encodeURIComponent(jQuery('#"+form.getFieldName()+"').val()),");
						queryColumns += form.getFieldName()+",";
						sb.append("<td>"+form.getCnName()+"：</td><td><input type=\"text\" readonly=readonly id=\""+form.getFieldName()+"\" onClick=\"WdatePicker()\" name=\""+form.getFieldName()+"\" value=\"\" class=\"tab_input\"/></td>");
						
					}else if("10".equals(type)){//选择部门
						qb.append("\""+form.getFieldName()+"\":encodeURIComponent(jQuery('#"+form.getFieldName()+"').val()),");
						queryColumns += form.getFieldName()+",";
						sb.append("<td>"+"<input type=\"hidden\" id=\""+form.getFieldName()+"\" name=\""+form.getFieldName()+"\">");
						sb.append(form.getCnName()+"：</td><td><input type=\"text\" readonly=readonly id=\"dept_"+form.getFieldName()+"\" name=\"dept_"+form.getFieldName()+"\" value=\"\" />");
						sb.append("<img src=\"web/images/form_icon_1.gif\" style=\"cursor:hand; vertical-align: middle;\" onclick=\"selectdept('"+form.getFieldName()+"')\" /></td>");
					}
					else if(!StringUtil.isEmpty(form.getForeignTableName())){//如果不满足上述条件  则判断外键是否存在
						qb.append("\""+form.getFieldName()+"\":encodeURIComponent(jQuery('#"+form.getFieldName()+"').val()),");
						queryColumns += form.getFieldName()+",";
						sb.append("<td>"+"<input type=\"hidden\" id=\""+form.getFieldName()+"\" name=\""+form.getFieldName()+"\">");
						sb.append(form.getCnName()+"：</td><td><input type=\"text\" readonly=readonly id=\"data_"+form.getFieldName()+"\" name=\"data_"+form.getFieldName()+"\" value=\"\" class=\"tab_input\"/>");
						sb.append("<img src=\"web/images/form_icon_1.gif\" style=\"cursor:hand; vertical-align: middle;\" onclick=\"selectData('"+form.getFieldName()+"','"+form.getForeignTableName()+"','"+form.getForeignCloumn()+"','"+form.getForeignDisCloumn()+"','"+form.getCnName()+"','"+form.getDefaultValue()+"','"+getRequest().getParameter("formid")+"')\" /></td>");
					}
					else{
						qb.append("\""+form.getFieldName()+"\":encodeURIComponent(jQuery('#"+form.getFieldName()+"').val()),");
						paras.append(form.getFieldName()+"=\"+encodeURIComponent(jQuery('#"+form.getFieldName()+"').val())+\"&");
						queryColumns += form.getFieldName()+",";
						sb.append("<td>"+form.getCnName()+"：</td><td><input type=\"text\" class=\"input\" style=\"width:150px;\" id=\""+form.getFieldName()+"\" name=\""+form.getFieldName()+"\" value=\"\" /></td>");
					}
				}
			}
			sb.append("</tr>");
			sb.append("</table>");

			if(isOrderBy.length()>0){
				isOrderBy = isOrderBy.substring(0,isOrderBy.length()-1);
			}
			/******************************************生成列表中关联的按钮 类型按钮  START***********************************************/
			StringBuffer buttonSb = new StringBuffer();
			String buttonSql = "select t.button_name,t.by_table_name_id,t.by_table_column from auto_forms_button t where t.this_table_name_id = "+formId +" and t.button_type = 0 ";
			List buttonList = autoService.getDatabySql(buttonSql);
			if(buttonList != null && buttonList.size() != 0 ){
				for (int j = 0; j < buttonList.size(); j++) {
					Object[] obj = (Object[])buttonList.get(j);
					buttonSb.append("<input type=\"button\" class=\"button_b\" value=\""+obj[0]+"\" onclick=\"buttonOnclick("+obj[1]+",'"+obj[0]+"','"+obj[2]+"')\"/>\r\n");
				}
			}
			/******************************************生成列表中关联的按钮  END*************************************************/
			getRequest().setAttribute("queryValue", qb);
			getRequest().setAttribute("queryColumns", queryColumns);
			getRequest().setAttribute("queryContent", sb);
			getRequest().setAttribute("formid", formId);
			getRequest().setAttribute("formnew", formnew);
			getRequest().setAttribute("colName", colName);
			getRequest().setAttribute("colModel", colModel);
			getRequest().setAttribute("columns", columns);
			getRequest().setAttribute("formWidth", formWidth);
			getRequest().setAttribute("formHeight", formHeight);
			getRequest().setAttribute("buttonList", buttonSb);
			getRequest().setAttribute("mobanid", mobanid);
			getRequest().setAttribute("isOrderBy", isOrderBy);
			getRequest().setAttribute("byTableColumn", byTableColumn);
			getRequest().setAttribute("byTableValue", byTableValue);
			getRequest().setAttribute("sbtype", sbtype);
			getRequest().setAttribute("flag", flag);
			getRequest().setAttribute("columnguolvsql",columnguolvsql);
			getRequest().setAttribute("menuName",menuName);
			getRequest().setAttribute("filemodeid",filemodeid);
			getRequest().setAttribute("parasContent", paras);
			
			return "viewAnalysislist";
		} catch (Exception e) {
			e.printStackTrace();
			return "error";
		}
	}
	
	
	public String gotoListForAnalysisData(){
		try {
			/****绑定按钮关联查询需要用的参数  START *****/
			String byTableColumn = getRequest().getParameter("byTableColumn");//外键名称
			String byTableValue = getRequest().getParameter("byTableValue");//外键值
			String mobanid = getRequest().getParameter("mobanid");//外键值
			/****绑定按钮关联查询需要用的参数  END *****/
			String formId = getRequest().getParameter("datainfoid");
			String sbtype = getRequest().getParameter("sbtype");
			String flag = getRequest().getParameter("flag");//技术条件模板流程审核查看信息标记
			String menuName = getRequest().getParameter("menuname");
			
			if(null!=menuName&&!"".equals(menuName)){
				menuName = StringUtil.encodingUrl(menuName);
			}
			
			//查询表单信息
			AutoFormsNew formnew =  autoFormService.getAutoFormsNewById(formId);
			String formWidth = "500";
			String formHeight = "500";
			String columnguolvsql = "";
			if( formnew.getFormwidth() != null && !"".equals(formnew.getFormwidth())){
				formWidth = formnew.getFormwidth();
			}
			if( formnew.getFormheight() != null && !"".equals(formnew.getFormheight())){
				formHeight = formnew.getFormheight();
			}
			if(  !"".equals(formnew.getColumnguolvsql())){
				columnguolvsql = formnew.getColumnguolvsql();
			}
			//查询字段信息
			List<AutoFormsField> formList = autoFormService.getAutoFormsFieldByformid(formId);
			String colName = "";
			String colModel = "";
			String columns = "";
			String queryColumns = "";
			String isOrderBy = "";
			StringBuffer sb = new StringBuffer();
			StringBuffer qb = new StringBuffer();
			StringBuffer paras = new StringBuffer();
			
			//String type = "";
			sb.append("<table  border='0' cellpadding='6' cellspacing='0' class='tabman' style='margin-bottom:0px'><tr>");
			int column = 1;//記錄是多少列的數據
			for (int i = 0; i < formList.size(); i++) {
				AutoFormsField form = formList.get(i);
				if(!"ID".equals(form.getFieldName())){
					//type =  form.getPageDisplayType().toString();
				}
				if("1".equals(String.valueOf(form.getIsOrderBy()))){//是否排序（0：否，1：是）
					isOrderBy += ""+ form.getFieldName() +" desc ,";
				}
				if("1".equals(String.valueOf(form.getIsListShow()))){//如果是列表显示  
					colName += "'"+ form.getCnName() +"',";
					int width = 100;
					if(form.getFieldListWidth()!=null){
						width = form.getFieldListWidth().intValue();
					}
					if("ID".equals(form.getFieldName())){
						colModel += "{name:'"+form.getFieldName()+"',index:'"+form.getFieldName()+"',key:true,hidden:true, width:"+width+",hidedlg:true},";
					}else{
						colModel += "{name:'"+form.getFieldName()+"',index:'"+form.getFieldName()+"', width:"+width+"},";
					}
					columns += form.getFieldName() + ",";
				}else{
					colName += "'"+ form.getCnName() +"',";
					int width = 100;
					if(form.getFieldListWidth()!=null){
						width = form.getFieldListWidth().intValue();
					}
					if("ID".equals(form.getFieldName())){
						colModel += "{name:'"+form.getFieldName()+"',index:'"+form.getFieldName()+"',key:true, width:"+width+",hidden:true,hidedlg:true},";
					}else{
						colModel += "{name:'"+form.getFieldName()+"',index:'"+form.getFieldName()+"', width:"+width+",hidden:true,hidedlg:true},";
					}
					columns += form.getFieldName() + ",";
				}
				if("1".equals(String.valueOf(form.getIsQueryField()))){//如果是查询条件
					String type = String.valueOf(form.getPageDisplayType());
					if (column %4 == 0) {
						  sb.append("</tr><tr>");
					}
					column++;
					if("1".equals(type)){//时间空间
						qb.append("\""+form.getFieldName()+"\":encodeURIComponent(jQuery('#"+form.getFieldName()+"').val()),");
						queryColumns += form.getFieldName()+",";
						sb.append("<td>"+form.getCnName()+"：</td><td><input type=\"text\" id=\""+form.getFieldName()+"\" onClick=\"WdatePicker()\" name=\""+form.getFieldName()+"\" value=\"\"  /></td>");
						
					}else if("2".equals(type)){//下拉菜单
						String defaultValue =form.getDefaultValue();
						if(!StringUtil.isEmpty(defaultValue)){
							String[] values = defaultValue.split(",");
							qb.append("\""+form.getFieldName()+"\":encodeURIComponent(jQuery('#"+form.getFieldName()+"').val()),");
							queryColumns += form.getFieldName()+",";
						    sb.append("<td>"+form.getCnName()+"：</td><td><select id=\""+form.getFieldName()+"\"  style=\"width:150px;\" class='fselect' name=\""+form.getFieldName()+"\" >");
						    sb.append("<option value=\"\">----请选择----</option>");
						    for(String value : values){
								sb.append("<option value=\""+value+"\">"+value+"</option>");
							}
							sb.append("</select></td>");
						}
					}else if("8".equals(type)){//操作时间
						qb.append("\""+form.getFieldName()+"\":encodeURIComponent(jQuery('#"+form.getFieldName()+"').val()),");
						queryColumns += form.getFieldName()+",";
						sb.append("<td>"+form.getCnName()+"：</td><td><input type=\"text\" readonly=readonly id=\""+form.getFieldName()+"\" onClick=\"WdatePicker()\" name=\""+form.getFieldName()+"\" value=\"\" class=\"tab_input\"/></td>");
						
					}else if("9".equals(type)){//操作日期
						qb.append("\""+form.getFieldName()+"\":encodeURIComponent(jQuery('#"+form.getFieldName()+"').val()),");
						queryColumns += form.getFieldName()+",";
						sb.append("<td>"+form.getCnName()+"：</td><td><input type=\"text\" readonly=readonly id=\""+form.getFieldName()+"\" onClick=\"WdatePicker()\" name=\""+form.getFieldName()+"\" value=\"\" class=\"tab_input\"/></td>");
						
					}else if("10".equals(type)){//选择部门
						qb.append("\""+form.getFieldName()+"\":encodeURIComponent(jQuery('#"+form.getFieldName()+"').val()),");
						queryColumns += form.getFieldName()+",";
						sb.append("<td>"+"<input type=\"hidden\" id=\""+form.getFieldName()+"\" name=\""+form.getFieldName()+"\">");
						sb.append(form.getCnName()+"：</td><td><input type=\"text\" readonly=readonly id=\"dept_"+form.getFieldName()+"\" name=\"dept_"+form.getFieldName()+"\" value=\"\" />");
						sb.append("<img src=\"web/images/form_icon_1.gif\" style=\"cursor:hand; vertical-align: middle;\" onclick=\"selectdept('"+form.getFieldName()+"')\" /></td>");
					}
					else if(!StringUtil.isEmpty(form.getForeignTableName())){//如果不满足上述条件  则判断外键是否存在
						qb.append("\""+form.getFieldName()+"\":encodeURIComponent(jQuery('#"+form.getFieldName()+"').val()),");
						queryColumns += form.getFieldName()+",";
						sb.append("<td>"+"<input type=\"hidden\" id=\""+form.getFieldName()+"\" name=\""+form.getFieldName()+"\">");
						sb.append(form.getCnName()+"：</td><td><input type=\"text\" readonly=readonly id=\"data_"+form.getFieldName()+"\" name=\"data_"+form.getFieldName()+"\" value=\"\" class=\"tab_input\"/>");
						sb.append("<img src=\"web/images/form_icon_1.gif\" style=\"cursor:hand; vertical-align: middle;\" onclick=\"selectData('"+form.getFieldName()+"','"+form.getForeignTableName()+"','"+form.getForeignCloumn()+"','"+form.getForeignDisCloumn()+"','"+form.getCnName()+"','"+form.getDefaultValue()+"','"+getRequest().getParameter("formid")+"')\" /></td>");
					}
					else{
						qb.append("\""+form.getFieldName()+"\":encodeURIComponent(jQuery('#"+form.getFieldName()+"').val()),");
						paras.append(form.getFieldName()+"=\"+encodeURIComponent(jQuery('#"+form.getFieldName()+"').val())+\"&");
						queryColumns += form.getFieldName()+",";
						sb.append("<td>"+form.getCnName()+"：</td><td><input type=\"text\" class=\"input\" style=\"width:150px;\" id=\""+form.getFieldName()+"\" name=\""+form.getFieldName()+"\" value=\"\" /></td>");
					}
				}
			}
			sb.append("</tr>");
			sb.append("</table>");
			
			queryColumns = getRequest().getParameter("queryColumn");
			String[] arrayColumns = queryColumns.split(",");
			String queryContent = "";
			for(int i=0;i<arrayColumns.length;i++){
				String queryValue = StringUtil.encodingUrl(getRequest().getParameter(arrayColumns[i]));
				queryContent +=arrayColumns[i]+"='+encodeURIComponent(encodeURIComponent(\""+queryValue+"\"))+'&";
			}
			if (queryContent.length()>0){
				queryContent = queryContent.substring(0,queryContent.length()-1);
			}

			if(colName.length()>0){
				colName = colName.substring(0,colName.length()-1);
			}
			if(colModel.length()>0){
				colModel = colModel.substring(0,colModel.length()-1);
			}
			if(columns.length()>0){
				columns = columns.substring(0,columns.length()-1);
			}
			if(isOrderBy.length()>0){
				isOrderBy = isOrderBy.substring(0,isOrderBy.length()-1);
			}
			/******************************************生成列表中关联的按钮 类型按钮  START***********************************************/
			StringBuffer buttonSb = new StringBuffer();
			String buttonSql = "select t.button_name,t.by_table_name_id,t.by_table_column from auto_forms_button t where t.this_table_name_id = "+formId +" and t.button_type = 0 ";
			List buttonList = autoService.getDatabySql(buttonSql);
			if(buttonList != null && buttonList.size() != 0 ){
				for (int j = 0; j < buttonList.size(); j++) {
					Object[] obj = (Object[])buttonList.get(j);
					buttonSb.append("<input type=\"button\" class=\"button_b\" value=\""+obj[0]+"\" onclick=\"buttonOnclick("+obj[1]+",'"+obj[0]+"','"+obj[2]+"')\"/>\r\n");
				}
			}
			/******************************************生成列表中关联的按钮  END*************************************************/
			getRequest().setAttribute("queryValue", qb);
			getRequest().setAttribute("queryColumns", queryColumns);
			getRequest().setAttribute("queryContent", queryContent);
			getRequest().setAttribute("formid", formId);
			getRequest().setAttribute("formnew", formnew);
			getRequest().setAttribute("colName", colName);
			getRequest().setAttribute("colModel", colModel);
			getRequest().setAttribute("columns", columns);
			getRequest().setAttribute("formWidth", formWidth);
			getRequest().setAttribute("formHeight", formHeight);
			getRequest().setAttribute("buttonList", buttonSb);
			getRequest().setAttribute("mobanid", mobanid);
			getRequest().setAttribute("isOrderBy", isOrderBy);
			getRequest().setAttribute("byTableColumn", byTableColumn);
			getRequest().setAttribute("byTableValue", byTableValue);
			getRequest().setAttribute("sbtype", sbtype);
			getRequest().setAttribute("flag", flag);
			getRequest().setAttribute("columnguolvsql",columnguolvsql);
			getRequest().setAttribute("menuName",menuName);
			getRequest().setAttribute("parasContent", paras);

			return "viewAnalysisdatalist";
		} catch (Exception e) {
			e.printStackTrace();
			return "error";
		}
	}
	
	/**
	 * 跳转页面前查询信息(流程中专用)
	 * author:lishu	 2013-10-25
	 */
	public String gotoListForFlow(){
		try {
			/****绑定按钮关联查询需要用的参数  START *****/
			String byTableColumn = getRequest().getParameter("byTableColumn");//外键名称
			String byTableValue = getRequest().getParameter("byTableValue");//外键值
			String operateType = getRequest().getParameter("operateType");//操作类型0：编辑，1：查看
			//fitterCondition 过滤条件（用户多样品，列表显示是编辑原始记录按钮还是查看原始记录按钮，0：编辑，1：查看）
			String fitterCondition = getRequest().getParameter("fitterCondition");
			String taskNo = getRequest().getParameter("taskNo");
			/****绑定按钮关联查询需要用的参数  END *****/
			String formId = getRequest().getParameter("formid");
			String taskId = getRequest().getParameter("taskId");//流程id
			String xzgyId = getRequest().getParameter("xzgyId");//工艺id
			//查询表单信息
			AutoFormsNew formnew =  autoFormService.getAutoFormsNewById(formId);
			String formWidth = "500";
			String formHeight = "500";
			if( formnew.getFormwidth() != null && !"".equals(formnew.getFormwidth())){
				formWidth = formnew.getFormwidth();
			}
			if( formnew.getFormheight() != null && !"".equals(formnew.getFormheight())){
				formHeight = formnew.getFormheight();
			}
			//查询字段信息
			List<AutoFormsField> formList = autoFormService.getAutoFormsFieldByformid(formId);
			String colName = "";
			String colModel = "";
			String columns = "";
			String queryColumns = "";
			StringBuffer sb = new StringBuffer();
			StringBuffer qb = new StringBuffer();
			//String type = "";
			for (int i = 0; i < formList.size(); i++) {
				AutoFormsField form = formList.get(i);
				if(!"ID".equals(form.getFieldName())){
					//type =  form.getPageDisplayType().toString();
				}
				if("1".equals(String.valueOf(form.getIsListShow()))){//如果是列表显示  
					colName += "'"+ form.getCnName() +"',";
					int width = 100;
					if(form.getFieldListWidth()!=null){
						width = form.getFieldListWidth().intValue();
					}
					if("ID".equals(form.getFieldName())){
						colModel += "{name:'"+form.getFieldName()+"',index:'"+form.getFieldName()+"',key:true, width:"+width+",hidedlg:true},";
					}else{
						colModel += "{name:'"+form.getFieldName()+"',index:'"+form.getFieldName()+"', width:"+width+"},";
					}
					columns += form.getFieldName() + ",";
				}else{
					colName += "'"+ form.getCnName() +"',";
					int width = 100;
					if(form.getFieldListWidth()!=null){
						width = form.getFieldListWidth().intValue();
					}
					if("ID".equals(form.getFieldName())){
						colModel += "{name:'"+form.getFieldName()+"',index:'"+form.getFieldName()+"',key:true, width:"+width+",hidden:true,hidedlg:true},";
					}else{
						colModel += "{name:'"+form.getFieldName()+"',index:'"+form.getFieldName()+"', width:"+width+",hidden:true,hidedlg:true},";
					}
					columns += form.getFieldName() + ",";
				}
				if("1".equals(String.valueOf(form.getIsQueryField()))){//如果是查询条件
					qb.append("\""+form.getFieldName()+"\":encodeURIComponent(jQuery('#"+form.getFieldName()+"').val()),");
					queryColumns += form.getFieldName()+",";
					sb.append(form.getCnName()+"：<input type=\"text\" class=\"input\" style=\"width:150px;\" id=\""+form.getFieldName()+"\" name=\""+form.getFieldName()+"\" value=\"\" />");
				}
			}
			
			if(colName.length()>0){
				colName = colName.substring(0,colName.length()-1);
			}
			if(colModel.length()>0){
				colModel = colModel.substring(0,colModel.length()-1);
			}
			if(columns.length()>0){
				columns = columns.substring(0,columns.length()-1);
			}
			
			/******************************************生成列表中关联的按钮 类型按钮  START***********************************************/
			StringBuffer buttonSb = new StringBuffer();
			String buttonSql = "select t.button_name,t.by_table_name_id,t.by_table_column from auto_forms_button t where t.this_table_name_id = "+formId +" and t.button_type = 0 ";
			List buttonList = autoService.getDatabySql(buttonSql);
			if(buttonList != null && buttonList.size() != 0 ){
				for (int j = 0; j < buttonList.size(); j++) {
					Object[] obj = (Object[])buttonList.get(j);
					buttonSb.append("<input type=\"button\" class=\"button_b\" value=\""+obj[0]+"\" onclick=\"buttonOnclick("+obj[1]+",'"+obj[0]+"','"+obj[2]+"')\"/>\r\n");
				}
			}
			/******************************************生成列表中关联的按钮  END*************************************************/
			
			getRequest().setAttribute("queryValue", qb);
			getRequest().setAttribute("queryColumns", queryColumns);
			getRequest().setAttribute("queryContent", sb);
			getRequest().setAttribute("formid", formId);
			getRequest().setAttribute("formnew", formnew);
			getRequest().setAttribute("colName", colName);
			getRequest().setAttribute("colModel", colModel);
			getRequest().setAttribute("columns", columns);
			getRequest().setAttribute("formWidth", formWidth);
			getRequest().setAttribute("formHeight", formHeight);
			getRequest().setAttribute("buttonList", buttonSb);
			getRequest().setAttribute("byTableColumn", byTableColumn);
			getRequest().setAttribute("byTableValue", byTableValue);
			getRequest().setAttribute("operateType", operateType);
			getRequest().setAttribute("fitterCondition", fitterCondition);
			getRequest().setAttribute("taskNo", taskNo);
			
			getRequest().setAttribute("taskId", taskId);
			getRequest().setAttribute("xzgyId", xzgyId);
			return "viewFlowlist";
		} catch (Exception e) {
			e.printStackTrace();
			return "error";
		}
	}
	
	/**
	 * 查询列表信息
	 * author:lishu	 2013-10-25
	 */
	public void queryAutoDataQuery() throws Exception{
		try {
			/****绑定按钮关联查询需要用的参数  START *****/
			String byTableColumn = getRequest().getParameter("byTableColumn");//外键名称
			String byTableValue = getRequest().getParameter("byTableValue");//外键值
			/****绑定按钮关联查询需要用的参数  END *****/
			String columns = getRequest().getParameter("columns");
			String tableName = getRequest().getParameter("tableName");
			String queryColumn = getRequest().getParameter("queryColumn");
			String formId = getRequest().getParameter("formid");
			String isOrderBy = getRequest().getParameter("isOrderBy");
			String sbtype = getRequest().getParameter("sbtype");
			String columnguolvsql =getRequest().getParameter("columnguolvsql");
			String pipelineno = getRequest().getParameter("pipelineno");
			String pipenetno = getRequest().getParameter("pipenetno");
			//String pipesectionnos = getRequest().getParameter("pipesectionnos");
			String pipesectionnos=null;
			String tasknos=null;
			String owner=getRequest().getParameter("owner");
			if(owner.equals("pipeSectionSearch"))
			{
				if (pipesectionnos==null){
					Object obj=getSession().getAttribute("pipesectionnos");
					if(obj!=null)
					{
						pipesectionnos=obj.toString();
					}
				}
			}
			if(owner.equals("TaskSearch"))
			{
				if (tasknos==null){
					Object obj=getSession().getAttribute("tasknos");
					if(obj!=null)
					{
						tasknos =obj.toString();
					}					
				}
			}
//			Object obj=getSession().getAttribute("pipesectionnos");
//			if(obj!=null)
//			{
//				pipesectionnos=obj.toString();
//			}
//			obj=getSession().getAttribute("tasknos");
//			if(obj!=null)
//			{
//				tasknos=obj.toString();
//			}
			String isXLJC=getRequest().getParameter("isXLJC");
			Map<String, String> filterMap = getPagerMap();
			if(!"".equals(columnguolvsql)){
				columnguolvsql = StringUtil.encodingUrl(columnguolvsql);
			}
			filterMap.put("roleid", this.getRole());
			filterMap.put("userid", this.getUserId());
			filterMap.put("columns", columns);
			filterMap.put("tableName", tableName);
			filterMap.put("queryColumn", queryColumn);
			filterMap.put("formId", formId);
			filterMap.put("byTableColumn", byTableColumn);
			filterMap.put("byTableValue", byTableValue);
			filterMap.put("sbtype", sbtype);
			filterMap.put("isOrderBy", isOrderBy);
			filterMap.put("columnguolvsql", columnguolvsql);
			if(pipelineno!=null)
			{
				filterMap.put("pipelineno", pipelineno);
			}
			if(pipenetno!=null)
			{
				filterMap.put("pipenetno", pipenetno);
			}
			if(pipesectionnos!=null)
			{
				filterMap.put("pipesectionnos", pipesectionnos);
			}
			if(tasknos!=null)
			{
				filterMap.put("tasknos", tasknos);
			}
			if(isXLJC.equals("true"))
			{
				filterMap.put("isXLJC", "true");
			}
			else
			{
				filterMap.put("isXLJC", "false");
			}
			//查询条件
			if(queryColumn!=null){
				String[] querycolumns = queryColumn.split(",");
				for(String column : querycolumns){
					String value = getRequest().getParameter(column);
					if(value!=null){
						String StringValue=StringUtil.encodingUrl(getRequest().getParameter(column)).trim();
						filterMap.put(column, StringValue);
					}
				}
			}
			String[] viewArray = columns.split(",");
			// 查询所有的数据			
			PageResult result = autoService.queryAutoFormDataQuery(filterMap);
			String returnStr = getColumnJson(result, viewArray);
		    setContentType();
			PrintWriter out = getResponse().getWriter();
			out.print(returnStr);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public void queryAutoData() throws Exception{
		try {
			
			String formIdChild = getRequest().getParameter("formIdChild");
			String fieldChild = getRequest().getParameter("fieldChild");
			String fieldParent = getRequest().getParameter("fieldParent");
			/****绑定按钮关联查询需要用的参数  START *****/
			String byTableColumn = getRequest().getParameter("byTableColumn");//外键名称
			String byTableValue = getRequest().getParameter("byTableValue");//外键值
			/****绑定按钮关联查询需要用的参数  END *****/
			String columns = getRequest().getParameter("columns");
			String tableName = getRequest().getParameter("tableName");
			String queryColumn = getRequest().getParameter("queryColumn");
			String queryColumnChild= getRequest().getParameter("queryColumnChild");
			String formId = getRequest().getParameter("formid");
			String isOrderBy = getRequest().getParameter("isOrderBy");
			String sbtype = getRequest().getParameter("sbtype");
			String columnguolvsql =getRequest().getParameter("columnguolvsql");
			Map<String, String> filterMap = getPagerMap();
			Map<String, String> filterMapChild = new HashMap() ;
			filterMapChild.put("formIdChild", formIdChild);
			filterMapChild.put("fieldChild", fieldChild);
			filterMapChild.put("fieldParent", fieldParent);
			filterMapChild.put("queryColumnChild", queryColumnChild);
			if(!"".equals(columnguolvsql)){
				columnguolvsql = StringUtil.encodingUrl(columnguolvsql);
			}
			filterMap.put("roleid", this.getRole());
			filterMap.put("userid", this.getUserId());
			filterMap.put("columns", columns);
			filterMap.put("tableName", tableName);
			filterMap.put("queryColumn", queryColumn);
			filterMap.put("formId", formId);
			filterMap.put("byTableColumn", byTableColumn);
			filterMap.put("byTableValue", byTableValue);
			filterMap.put("sbtype", sbtype);
			filterMap.put("isOrderBy", isOrderBy);
			filterMap.put("columnguolvsql", columnguolvsql);
			//查询条件
			if(queryColumn!=null){
				String[] querycolumns = queryColumn.split(",");
				for(String column : querycolumns){
					String value = getRequest().getParameter(column);
					if(value!=null){
						String StringValue=StringUtil.encodingUrl(getRequest().getParameter(column)).trim();
						filterMap.put(column, StringValue);
					}
				}
			}
			//子表查询条件
			if(queryColumnChild!=null){
				String[] querycolumns = queryColumnChild.split(",");
				for(String column : querycolumns){
					String value = getRequest().getParameter(column);
					if(value!=null){
						String StringValue=StringUtil.encodingUrl(getRequest().getParameter(column)).trim();
						filterMapChild.put(column, StringValue);
					}
				}
			}
			String[] viewArray = columns.split(",");
			// 查询所有的数据
			PageResult result = autoService.queryAutoFormData(filterMap,filterMapChild);
			String returnStr = getColumnJson(result, viewArray);
		    setContentType();
			PrintWriter out = getResponse().getWriter();
			out.print(returnStr);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	
	/**
	 * 查询列表信息
	 * author:lishu	 2013-10-25
	 */
	public void queryAnalysisData() throws Exception{
		try {
			/****绑定按钮关联查询需要用的参数  START *****/
			String byTableColumn = getRequest().getParameter("byTableColumn");//外键名称
			String byTableValue = getRequest().getParameter("byTableValue");//外键值
			/****绑定按钮关联查询需要用的参数  END *****/
			String columns = getRequest().getParameter("columns");
			String tableName = getRequest().getParameter("tableName");
			String queryColumn = getRequest().getParameter("queryColumn");
			String formId = getRequest().getParameter("formid");
			String isOrderBy = getRequest().getParameter("isOrderBy");
			String sbtype = getRequest().getParameter("sbtype");
			String columnguolvsql =getRequest().getParameter("columnguolvsql");
			Map<String, String> filterMap = getPagerMap();
			if(!"".equals(columnguolvsql)){
				columnguolvsql = StringUtil.encodingUrl(columnguolvsql);
			}
			filterMap.put("roleid", this.getRole());
			filterMap.put("userid", this.getUserId());
			filterMap.put("columns", columns);
			filterMap.put("tableName", tableName);
			filterMap.put("queryColumn", queryColumn);
			filterMap.put("formId", formId);
			filterMap.put("byTableColumn", byTableColumn);
			filterMap.put("byTableValue", byTableValue);
			filterMap.put("sbtype", sbtype);
			filterMap.put("isOrderBy", isOrderBy);
			filterMap.put("columnguolvsql", columnguolvsql);
			//查询条件
			if(queryColumn!=null){
				String[] querycolumns = queryColumn.split(",");
				for(String column : querycolumns){
					String value = getRequest().getParameter(column);
					if(value!=null){
						String StringValue=StringUtil.encodingUrl(getRequest().getParameter(column)).trim();
						filterMap.put(column, StringValue);
					}
				}
			}
			String[] viewArray = columns.split(",");
			// 查询所有的数据
			PageResult result = autoService.queryAutoAnalysisFormData(filterMap);
			String returnStr = getColumnJson(result, viewArray);
		    setContentType();
			PrintWriter out = getResponse().getWriter();
			out.print(returnStr);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	/**
	 * 获取表单的列表
	 * author:lishu	 2014-3-4
	 */
	public void queryAutoPageData() throws Exception{
		try {
			String formid = getRequest().getParameter("formid");
			String tablejsid = getRequest().getParameter("tablejsid");
			String formstateid = getRequest().getParameter("formstateid");
			//查询表单信息
			AutoFormsNew formnew1 =  autoFormService.getAutoFormsNewById(formid);
			String columnName = formnew1.getColumnCnName();
			String columnSql = formnew1.getColumnSql();
			String otherColumnSql = formnew1.getOtherColumnSql();//其他sql
			if(!StringUtil.isEmpty(otherColumnSql) && "false".equals(formstateid)){
				columnSql = otherColumnSql;
			}
			String[] columnNames = columnName.split(",");
			String[] viewArray = new String[columnNames.length];
			for (int i = 0; i < columnNames.length; i++) {
				viewArray[i] = "name" + String.valueOf(i);
			} 
			Map<String, String> filterMap = getPagerMap();
			filterMap.put("columnSql", columnSql.replaceAll("#param#", tablejsid));
			// 查询所有的数据
			PageResult result = autoService.queryAutoPageFormData(filterMap);
			String returnStr = getColumnJson(result, viewArray);
			setContentType();
			PrintWriter out = getResponse().getWriter();
			//System.out.println("--!"+returnStr+"--!");
			out.print(returnStr);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	/**
	 * 查询已选项目的所有单价之和
	 * @author zhn
	 * @date Apr 4, 2014 4:49:59 PM
	 * @throws Exception
	 */
	public void findProject() throws Exception{
		try {
			String flowid = getRequest().getParameter("flowid");
			String taskId = getRequest().getParameter("taskId");
			List list = autoService.findProject(flowid,taskId);
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	/**
	 * 查询列表信息
	 * author:lishu	 2013-10-25
	 */
	public void queryChooseData() throws Exception{
		try {
			String media=getRequest().getParameter("media");
			String byTableValueId = getRequest().getParameter("byTableValueId");
			String columns = getRequest().getParameter("columns");
			//String columns = getRequest().getParameter("colname");
			String tableName = getRequest().getParameter("tableName");
			String queryColumn = getRequest().getParameter("queryColumn");
			String queryValue = getRequest().getParameter("queryValue");
			String disname = getRequest().getParameter("disname");
			String flowid = getRequest().getParameter("flowid");
			String formid = getRequest().getParameter("formid");
			String fileName =getRequest().getParameter("fileName");
			String unittype =getRequest().getParameter("unittype");
			String orgid =getRequest().getParameter("orgid");
			String cnname =getRequest().getParameter("cnname");
			
			String fittercondition ="";
			if(null!=formid&&!"".equals(formid)&&!"null".equals(formid)){
				List<AutoFormsField> fieldList = autoFormService.getAutoFormsFieldByformid(formid);
				for(AutoFormsField field :fieldList){
					if(field.getFieldName().equals(fileName)){
						if(field.getFitterCondition()!=null&&!"".equals(field.getFitterCondition())){
							fittercondition=field.getFitterCondition();
						}
					}
				}
			}
			Map<String, String> filterMap = getPagerMap();
			filterMap.put("orgid", orgid);
			filterMap.put("unittype", unittype);
			filterMap.put("flowid", flowid);
			filterMap.put("byTableValueId", byTableValueId);
			filterMap.put("formid", formid);
			filterMap.put("fitterCondition", fittercondition);
			filterMap.put("roleid", this.getRole());
			filterMap.put("userid", this.getUserId());
			filterMap.put("columns", columns);
			filterMap.put("tableName", tableName);
			filterMap.put("queryColumn", queryColumn);
			filterMap.put("queryValue", queryValue);
			filterMap.put("disname",disname==null?"":disname);
			filterMap.put("media", media);
			filterMap.put("unittype", cnname);
			//查询条件
			if(queryColumn!=null){
				String[] querycolumns = queryColumn.split(",");
				for(String column : querycolumns){
					String value = getRequest().getParameter(column);
					if(value!=null&&!"".equals(value)){
						value = StringUtil.encodingUrl(String.valueOf(value)).trim();
						filterMap.put(column, value);
					}
				}
			}
			String[] viewArray = columns.split(",");
			// 查询所有的数据
			PageResult result = autoService.queryChooseFormData(filterMap);
			String returnStr = getColumnJson(result, viewArray);
			setContentType();
			PrintWriter out = getResponse().getWriter();
			//System.out.println("--!"+returnStr+"--!");
			out.print(returnStr);
		} catch (Exception e) {
			e.printStackTrace();
		}
	} 
	/**
	 * 跳转到添加页面
	 * author:lishu	 2013-10-28
	 */
	public String gotoAdd() {
		try {
			/****绑定按钮关联查询需要用的参数  START *****/
			String byTableColumn = getRequest().getParameter("byTableColumn");//外键名称
			String byTableValueId = getRequest().getParameter("byTableValue");
			String flowtaskid =  getRequest().getParameter("flowtaskid");
			String sign =  getRequest().getParameter("sign");  //0：常规检测流程添加样品
			/****绑定按钮关联查询需要用的参数  END *****/
			
			String formid = getRequest().getParameter("formid");
			//查询表单信息
			AutoFormsNew formnew =  autoFormService.getAutoFormsNewById(formid);
			//查询字段信息
			List<AutoFormsField> fieldList = autoFormService.getAutoFormsFieldByformid(formid);
			StringBuffer sb = new StringBuffer();
			String columns = "";
			String columnHidden = "";
			/******************************************生成页面  START*************************************************/
			if(fieldList.size()>0){//如果字段信息为空
				String formColumn = String.valueOf(formnew.getFormColumn());
				sb.append("<br><br>");
				if("1".equals(formColumn) || formnew.getFormColumn()==null){//如果是一列显示
					for(AutoFormsField field : fieldList){
						//是否页面显示
						if("0".equals(field.getIsPageShow().toString())){
							//按钮关联的外键放到隐藏域里
							if(byTableColumn.equals(field.getFieldName())){
								columnHidden += "<input type='hidden' id=\""+field.getFieldName()+"\" name=\""+field.getFieldName()+"\" value=\""+byTableValueId+"\"/>";
								if(!"ID".equals(field.getFieldName())){
									columns += field.getFieldName() + ",";
								}
							}
							columnHidden += "<input type='hidden' id=\""+field.getFieldName()+"\" name=\""+field.getFieldName()+"\"/>";
							continue;
						}
						if(!field.getFieldName().equals("ID")){//除了ID的添加
							columns += field.getFieldName() + ",";
							sb.append("<tr>");
							sb.append("<td align=\"right\">"+field.getCnName()+"：</td>");
							sb.append("<td align=\"left\">");
							sb.append(getAddHtml(field));
							sb.append("</td>");
							sb.append("</tr>");
						}
					}
				}else if("2".equals(formColumn)){//如果是两列显示
					int j = 1;
					for (int i = 0; i < fieldList.size(); i++) {
						AutoFormsField field1 = fieldList.get(i);
						//是否页面显示
						if("0".equals(field1.getIsPageShow().toString())){
							//按钮关联的外键放到隐藏域里
							if(byTableColumn.equals(field1.getFieldName())){
								columnHidden += "<input type='hidden' id=\""+field1.getFieldName()+"\" name=\""+field1.getFieldName()+"\" value=\""+byTableValueId+"\"/>";
								if(!"ID".equals(field1.getFieldName())){
									columns += field1.getFieldName() + ",";
								}
							}
							columnHidden += "<input type='hidden' id=\""+field1.getFieldName()+"\" name=\""+field1.getFieldName()+"\"/>";
							continue;
						}
						if(!field1.getFieldName().equals("ID")){//除了ID的添加
							//按钮关联的外键放到隐藏域里
							if(byTableColumn.equals(field1.getFieldName())){
								columnHidden += "<input type='hidden' id=\""+field1.getFieldName()+"\" name=\""+field1.getFieldName()+"\" value=\""+byTableValueId+"\"/>";
								if(!"ID".equals(field1.getFieldName())){
									columns += field1.getFieldName() + ",";
								}
							}else{
								if(j%2==1){
									sb.append("<tr>");
								}
								String type = String.valueOf(field1.getPageDisplayType());
								String sfhebing  = String.valueOf(field1.getSfhebing());
								columns += field1.getFieldName() + ",";
								sb.append("<td align=\"right\">"+field1.getCnName()+"：</td>");
								if("3".equals(type)&&"1".equals(sfhebing)&&j%2==1){
									sb.append("<td align=\"left\" colspan=\"3\">");
								}else{
									sb.append("<td align=\"left\">");
								}
								sb.append(getAddHtml(field1));
								sb.append("</td>");
								if(j%2==0){
									sb.append("</tr>");
								}
								j++;
							}
						}
					} 
				}
			}
			sb.append(columnHidden);
			/******************************************生成页面  END*************************************************/
			getRequest().setAttribute("columns", columns);
			getRequest().setAttribute("tableContent", sb);
			getRequest().setAttribute("formnew", formnew);
			getRequest().setAttribute("fieldList", fieldList);
			getRequest().setAttribute("formid", formid);
			getRequest().setAttribute("flowtaskid",flowtaskid);
			getRequest().setAttribute("sign",sign);
			return "gotoadd";
		} catch (Exception e) {
			e.printStackTrace();
			return ERROR;
		}
	}
	/**
	 * 拼接html語句（添加的）
	 * author:lishu	 2013-10-29
	 */
	public String  getAddHtml(AutoFormsField field){
		StringBuffer sb = new StringBuffer();
		String type = String.valueOf(field.getPageDisplayType());
		String sfhebing  = String.valueOf(field.getSfhebing()); //列是否合并
		String defaultValue = field.getDefaultValue();//獲取默認值
		String eventType = field.getEventType();//事件类型
		String eventName = field.getEventName();//事件名称
		String isReadOnly = field.getIsReadOnly().toString();//页面是否只读（0：否，1：是）
		String readOnlyText = ""; //是否只读 readonly="readonly"
		String event = "";
		if(!StringUtil.isEmpty(eventType)){
			event = eventType + "='" + eventName + "'";
		}
		String isreadOnly = "";
		String bitian = " ";
		String message = "";
		String textLength = "";
		if(field.getIsReadOnly()==1){
			if("2".equals(type)||"4".equals(type)||"5".equals(type)){
				isreadOnly = " disabled ='true' ";
			}else{
				isreadOnly = " readonly = readonly ";
			}
		}
		if("NUMBER".equals(field.getFieldType())&&type.equals("0")){
			message = "只允许输入数字";
			bitian += "  class='easyui-numberbox'  missingMessage='"+message+"' ";
			if("0".equals(type)){
				textLength = "100";
			}
			else if("3".equals(type)){
				textLength = "4000";
			}
		}else{
			if("1".equals(field.getAuthenticationType())){
				message = "必填";
				bitian += " class='easyui-validatebox' ";
			}
			if(!"".equals(field.getFieldLength())){
				if("0".equals(type)){
					textLength =field.getFieldLength()+"";
				}else {
					textLength = field.getFieldLength()+"";
				}
			}else{
				if("0".equals(type)){
					textLength = " 50";
				}
				else{
					textLength = "4000";
				}
			}
		}
		if("1".equals(field.getAuthenticationType())){
			message = "必填";
			bitian += " required missingMessage='"+message+"' ";
		}
		if("1".equals(isReadOnly)){
			readOnlyText = "readonly=readonly";
		}else{
			readOnlyText = "";
		}
		//页面显示类型（0：文本，1：时间空间，2：下拉菜单，3：文本域,4：单选框，5：复选框，6：操作人，7操作部门，8操作时间）
		if("1".equals(type)){//时间空间
			if("1".equals(isReadOnly)){
				sb.append("<input "+readOnlyText+" type=\"text\" id=\""+field.getFieldName()+"\" style=\"border: 1px solid #999;padding: 5px;width: 200px;\" name=\""+field.getFieldName()+"\" "+bitian+" value=\"\" />");
			}else{
				sb.append("<input "+readOnlyText+" type=\"text\" id=\""+field.getFieldName()+"\" style=\"border: 1px solid #999;padding: 5px;width: 200px;\" onClick=\"WdatePicker()\" name=\""+field.getFieldName()+"\" "+bitian+" value=\"\" />");
			}
		}else if("2".equals(type)){//下拉菜单
			if(!StringUtil.isEmpty(defaultValue)){
				String[] values = defaultValue.split(",");
				if("1".equals(isReadOnly)){
					sb.append("<select id=\""+field.getFieldName()+"\" disabled class='fselect1' name=\""+field.getFieldName()+"\" "+event+" "+bitian+" >");
				}else{
					sb.append("<select id=\""+field.getFieldName()+"\" class='fselect1' name=\""+field.getFieldName()+"\" "+event+" "+bitian+" >");
				}
				for(String value : values){
					sb.append("<option value=\""+value+"\">"+value+"</option>");
				}
				sb.append("</select>");
			}
		}else if("3".equals(type)){//文本域
		     if("0".equals(sfhebing)){
		    	 sb.append("<textarea "+readOnlyText+" rows=\"8\" cols=\"31\" id=\""+field.getFieldName()+"\" name=\""+field.getFieldName()+"\" style=\"border: 1px solid #999;padding: 5px;width: 200px;\" "+bitian+"></textarea>");
		     }else{
		    	 sb.append("<textarea "+readOnlyText+" rows=\"8\" cols=\"31\" id=\""+field.getFieldName()+"\" name=\""+field.getFieldName()+"\" style=\"border: 1px solid #999;padding: 5px;width: 675px;\" "+bitian+"></textarea>");
		     }
		
		}else if("4".equals(type)){//单选框
			if(!StringUtil.isEmpty(defaultValue)){
				String[] values = defaultValue.split(",");
				for(String value : values){
					if("1".equals(isReadOnly)){
						sb.append("<input type=\"radio\" disabled name=\""+field.getFieldName()+"\" "+bitian+" value=\""+value+"\" "+event+">" + value);
					}else{
						sb.append("<input type=\"radio\" name=\""+field.getFieldName()+"\" "+bitian+" value=\""+value+"\" "+event+">" + value);
					}
				}
			}
		}else if("5".equals(type)){//复选框
			if(!StringUtil.isEmpty(defaultValue)){
				String[] values = defaultValue.split(",");
				int j = 0;
				String str="";
				for (int i = 0; i < values.length; i++) {
					if(i==values.length-1&&"1".equals(field.getAuthenticationType())){
						str =" class='easyui-validatebox' validType=\"checkbox['pageFrom','"+field.getFieldName()+"']\"";
					}
					sb.append("<input type=\"checkbox\" style=\"border:none;width:20px; padding-left:0;height:auto;line-height:auto;\" " + isreadOnly+str+
							"name=\""+field.getFieldName()+"\" value=\""+values[i]+"\">" + values[i]);
					if(j%MOD_CHECK==1){
						sb.append("<br/>");
					}
					j++;
				}
			}
		}else if("6".equals(type)){//操作人
			sb.append("<input type=\"text\" readonly=readonly id=\""+field.getFieldName()+"\" name=\""+field.getFieldName()+"\" value=\""+getUserNM()+"\" style=\"border: 1px solid #999;padding: 5px;width: 200px;\"   "+bitian+"/>");
		}else if("7".equals(type)){//操作部门
			sb.append("<input type=\"text\" readonly=readonly id=\""+field.getFieldName()+"\" name=\""+field.getFieldName()+"\" value=\""+getDeptName()+"\" style=\"border: 1px solid #999;padding: 5px;width: 200px;\" "+bitian+"/>");
		}else if("8".equals(type)){//操作时间
			sb.append("<input type=\"text\" readonly=readonly id=\""+field.getFieldName()+"\" name=\""+field.getFieldName()+"\" value=\""+DateUtilsAll.dateToString(new Date())+"\"  style=\"border: 1px solid #999;padding: 5px;width: 200px;\"   "+bitian+"/>");
		}else if("9".equals(type)){//操作日期
			sb.append("<input type=\"text\" readonly=readonly id=\""+field.getFieldName()+"\" name=\""+field.getFieldName()+"\" value=\""+DateUtilsAll.dateToStringShort(new Date())+"\" style=\"border: 1px solid #999;padding: 5px;width: 200px;\"  "+bitian+"/>");
		}else if("10".equals(type)){//选择部门
			sb.append("<input type=\"hidden\" id=\""+field.getFieldName()+"\" "+bitian+" name=\""+field.getFieldName()+"\">");
			sb.append("<input type=\"text\" readonly=readonly id=\"dept_"+field.getFieldName()+"\" name=\"dept_"+field.getFieldName()+"\" style=\"border: 1px solid #999;padding: 5px;width: 200px;\"  value=\"\" />");
			if("1".equals(field.getAuthenticationType())){
				sb.append("<img src=\"images/xh.png\" align=\"absmiddle\"></img>");
			}
			sb.append("<img src=\"web/images/form_icon_1.gif\" style=\"cursor:hand; vertical-align: middle;\" onclick=\"selectdept('"+field.getFieldName()+"')\" />");
		}else if("11".equals(type)){//选择人员
			sb.append("<input type=\"hidden\" id=\""+field.getFieldName()+"\"  name=\""+field.getFieldName()+"\">");
			sb.append("<input type=\"text\" readonly=readonly id=\"user_"+field.getFieldName()+"\" "+bitian+" name=\"user_"+field.getFieldName()+"\" style=\"border: 1px solid #999;padding: 5px;width: 200px;\" value=\"\" />");
			if("1".equals(field.getAuthenticationType())){
				sb.append("<img src=\"images/xh.png\" align=\"absmiddle\"></img>");
			}
			sb.append("<img src=\"web/images/form_icon_1.gif\" style=\"cursor:hand; vertical-align: middle;\" onclick=\"selectperson('"+field.getFieldName()+"')\" />");
		}else if(!StringUtil.isEmpty(field.getForeignTableName())){//如果不满足上述条件  则判断外键是否存在
			//System.out.println("................................\n");
			sb.append("<input type=\"hidden\" id=\"test"+field.getFieldName()+"\"  name=\"test"+field.getFieldName()+"\">");
			//sb.append("<input type=\"text\" readonly=readonly id=\"data_"+field.getFieldName()+"\" "+bitian+" name=\"data_"+field.getFieldName()+"\" style=\"border: 1px solid #999;padding: 5px;width: 200px;\"  value=\"\" />");
			sb.append("<input type=\"text\" readonly=readonly id=\""+field.getFieldName()+"\" "+bitian+" name=\""+field.getFieldName()+"\" style=\"border: 1px solid #999;padding: 5px;width: 200px;\"  value=\"\" />");	
			if("1".equals(field.getAuthenticationType())){
				sb.append("<img src=\"images/xh.png\" align=\"absmiddle\"></img>");
			}
			sb.append("<img src=\"web/images/form_icon_1.gif\" style=\"cursor:hand; vertical-align: middle;\" onclick=\"selectData('"+field.getFieldName()+"','"+field.getForeignTableName()+"','"+field.getForeignCloumn()+"','"+field.getForeignDisCloumn()+"','"+field.getCnName()+"','"+field.getDefaultValue()+"','"+getRequest().getParameter("formid")+"')\" />");
		}else if("13".equals(type)){//文件上传
			String id = GenerateSequenceUtil.generateSequenceNo();
			sb.append("<a href='auto!toUploadcontrol.action?fileid="+id+"' target='_blank'>文件上传</a>");
			sb.append("<input type=\"hidden\"  id=\""+field.getFieldName()+"\" name=\""+field.getFieldName()+"\" class=\"button_b\" value='"+id+"' />");
		}else if("19".equals(type)){//编号规则
			String no = autoFormService.queryCunstomNumber(field.getCustomNum(), field.getCustomId());
			sb.append("<input type=\"text\" style=\"border: 1px solid #999;padding: 5px;width: 200px;\"  readonly=readonly id=\""+field.getFieldName()+"\" name=\""+field.getFieldName()+"\" value=\""+no+"\" "+bitian+"/>");
		}else if("20".equals(type)){//试验编号
				sb.append("<input type=\"text\"   id=\""+field.getFieldName()+"\"  name=\""+field.getFieldName()+"\" readonly=\"readonly\" "+bitian+" style=\"border: 1px solid #999;padding: 5px;width: 200px;\"/>");
				sb.append("<input type=\"hidden\"   id=\"TEST_ID\"  name=\"TEST_ID\"  style=\"border: 1px solid #999;padding: 5px;width: 200px;\"/>");
				sb.append("<img src=\"web/images/form_icon_1.gif\" width=\"23\" height=\"23\" border=\"0\" onclick=\"chooseCustomNo('"+field.getFieldName()+"');\" title=\"选择\" style=\"margin-bottom:-6px;cursor:hand;\" />");
		}else{
			if(!"".equals(field.getDefaultValue()) && null!=field.getDefaultValue()){//显示只读字段默认值
				sb.append("<input "+readOnlyText+" type=\"text\" "+event+" id=\""+field.getFieldName()+"\" "+bitian+" name=\""+field.getFieldName()+"\" style=\"border: 1px solid #999;padding: 5px;width: 200px;\"  value=\""+defaultValue+"\" />");
			}else{
				sb.append("<input "+readOnlyText+" type=\"text\" "+event+" id=\""+field.getFieldName()+"\" "+bitian+" name=\""+field.getFieldName()+"\" style=\"border: 1px solid #999;padding: 5px;width: 200px;\"  value=\"\" />");
			}
			
		}
		if("1".equals(field.getAuthenticationType())&&(!"10".equals(type)&&!"11".equals(type)&&StringUtil.isEmpty(field.getForeignTableName()))){
			sb.append("<img src=\"images/xh.png\" align=\"absmiddle\"></img>");
		}
		return sb.toString();
	}
	
	public String toUploadcontrol(){
		String fileid = getRequest().getParameter("fileid");
		if(fileid.equals("null"))
		{
			fileid="";
		}
		getRequest().setAttribute("fileid", fileid);
		return "uploadcontrol";
	}
	
	
	public void saveForm() throws Exception{
		PrintWriter out = getResponse().getWriter();
		try {
			String formid = getRequest().getParameter("formid");
			String annexIds = "";
			String[] allAnnexId =null;
			String flag = "1";//发动机平台区别号是否存在的标识 
			if(flag.equals("1")){
				//存文件
				List files = getUploadfile();
				if (files!=null)
				{
					for (int i = 0 ; i < files.size() ; i++) 
					{ 
						String fileName = (String) getUploadfileFileName().get(i);
						String fileType = fileName.substring((fileName.lastIndexOf("."))+1, fileName.length());
						File ff = new File(files.get(i).toString());
						if(ff.length()>0)
						{
							ActionContext ac = ActionContext.getContext();
					        ServletContext sc = (ServletContext) ac.get(ServletActionContext.SERVLET_CONTEXT);
					        String url = getRequest().getSession().getAttribute("SYS_FILEPATH").toString();
					        SimpleDateFormat simpleDateFormat =  new SimpleDateFormat("yyyyMM");
						    String date = simpleDateFormat.format(new Date());
						    url = url +"/annex/"+date;
							File file = new File(url);
							if ( ! (file.exists())  &&   ! (file.isDirectory()))  {
				                 boolean  creadok  =  file.mkdirs();
				                 if (creadok)  {
				                    System.out.println( " ok:创建文件夹成功！ " );
				                } else  {
				                    System.out.println( " err:创建文件夹失败！ " );                    
				                } 
				            } 
							String address = url + "/" + getUploadfileFileName().get(i);
							FileOutputStream fos = new FileOutputStream(address); 
							FileInputStream fis = new FileInputStream(files.get(i).toString()); 
							byte[] buffer = new byte[1024]; 
							int len = 0; 
							while ((len = fis.read(buffer)) > 0) 
							{ 
								fos.write(buffer, 0, len);
							} 
							fos.close();
							fis.close();
							//将附件保存到Tdm_annex中
							TdmAnnex annex = new TdmAnnex();
							annex.setFileName(getUploadfileFileName().get(i).toString());
							annex.setFilePath("/annex/"+date+"/" + getUploadfileFileName().get(i));
							annex.setAnnexType(1l);
							annex.setCreateTime(new Date());
							annex.setCreateUserid(Long.parseLong(this.getUserId()));
							annex.setCreateUsername(this.getUserName());
							String annexId = autoService.saveObject(annex);
							annexIds = annexIds +","+annexId;
						}
					}
				}
				
				if(!"".equals(annexIds)){
					annexIds = annexIds.substring(1);
					allAnnexId = annexIds.split(",");
				}
				String columns = getRequest().getParameter("columns");//页面所有的列
				
				
				//取得字段类型是文件的元素
				List fileColumnList = new ArrayList();
				List checkBoxList = new ArrayList();
				List<AutoFormsField> fieldList = autoFormService.getAutoFormsFieldByformid(formid);
				for(int i = 0; i<fieldList.size();i++){
					AutoFormsField aff = fieldList.get(i);
					if(aff.getPageDisplayType()!=null&&"13".equals(aff.getPageDisplayType().toString())){
						fileColumnList.add(aff.getFieldName());
					}else if(aff.getPageDisplayType()!=null&&"5".equals(aff.getPageDisplayType().toString())){
						checkBoxList.add(aff.getFieldName());
					}
				}
				
				//查询表单信息
				AutoFormsNew formnew =  autoFormService.getAutoFormsNewById(formid);
				String bsql = "ID,";//拼接sql语句
				String asql = "SEQ_"+formnew.getFormEnName()+".nextval,";
				if(columns != null){
					String[] columnss = columns.split(",");
					int fileNameIndex = 0;
					//字段索引
					int fieldIndex=1;				
					for(String column : columnss){
						String columnValue = "";
						bsql += column + ",";
						if(checkBoxList.contains(column)){//如果是复选框
							String[] values = getRequest().getParameterValues(column);
							columnValue=org.apache.commons.lang.StringUtils.join(values,",");
						}else{
							columnValue = getRequest().getParameter(column);
						}
						if(columnValue == null){
							asql += "'',";
						}else{
							AutoFormsField aff = fieldList.get(fieldIndex);
							if(!"".equals(columnValue)&&aff.getFieldType().equals("DATE"))
							{
								asql +="to_date('"+columnValue+"','YYYY-MM-DD'),";		
							}
							else
							{
								asql += "'"+columnValue+"',";
							}					
							  //asql += "'" + columnValue +"',";
						}
						fieldIndex++;
					}
					String sql = "insert into "+formnew.getFormEnName()+"("+bsql.substring(0,bsql.length()-1)+")values("+asql.substring(0,asql.length()-1)+")";
					autoService.executeSql(sql);
				}
				out.print("{\"result\":\"success\"}");
			}else{
				out.print("{\"result\":\"exist\"}");
			}
		} catch (Exception e) {
			e.printStackTrace();
			out.print("{\"result\":\"error\"}");
		}
	}
	/**
	 * 跳转到修改页面
	 * author:lishu	 2013-10-28
	 */
	public String gotoUpdate(){
		try {
			/****绑定按钮关联查询需要用的参数  START *****/
			String byTableColumn = getRequest().getParameter("byTableColumn");//外键名称
			String byTableValueId = getRequest().getParameter("byTableValue");
			String flowtaskid =  getRequest().getParameter("flowtaskid");
			/****绑定按钮关联查询需要用的参数  END *****/
			String formid = getRequest().getParameter("formid");
			String id = getRequest().getParameter("id");
			//查询表单信息
			AutoFormsNew formnew = autoFormService.getAutoFormsNewById(formid);
			//查询字段信息
			List<AutoFormsField> fieldList = autoFormService.getAutoFormsFieldByformid(formid);
			
			String columns = "";
			String columnHidden = "";
			StringBuffer sb = new StringBuffer();
			for(AutoFormsField field : fieldList){
					columns += field.getFieldName() + ",";
			}
			if(columns.length()>0){
				columns = columns.substring(0,columns.length()-1);
			}
			String sql = "select "+columns+" from " + formnew.getFormEnName() + " where ID="+id;
			List list = autoService.getDatabySql(sql);//查询所有的数据项
			Object[] objs = null;
			if(list.size()>0){
				objs = (Object[])list.get(0);
			}
			//拼接页面字段
			String formColumn = String.valueOf(formnew.getFormColumn());
			if("1".equals(formColumn)){//如果是一列显示
				for(int i=0;i<fieldList.size();i++){
					AutoFormsField field = fieldList.get(i);
						//页面是否显示
						if("0".equals(field.getIsPageShow().toString())){
							columnHidden += "<input type='hidden' id=\""+field.getFieldName()+"\" name=\""+field.getFieldName()+"\" value=\""+objs[i]+"\"  />";
							continue;
						}
						if(field.getFormsId()==4361&&"T_QIANZHANGIMAGE".equals(field.getFieldName())){
							sb.append("<tr>");
							sb.append("<td align=\"right\"></td>");
							sb.append("<td align=\"left\">");
							sb.append(" <img id=\""+field.getFieldName()+"_Img\" style=\"width:120px; height:120px;\" src=\"images/insertpicture.png\"/>");
							sb.append("</td>");
							sb.append("</tr>");
						}
						sb.append("<tr>");
						if(!"主键".equals(field.getCnName())){
							sb.append("<td align=\"right\">"+field.getCnName()+"：</td>");
						}
						sb.append("<td align=\"left\">");
						//sb.append("<input type=\"text\" id=\""+field.getFieldName()+"\" name=\""+field.getFieldName()+"\" value=\""+objs[i]+"\" />");
						sb.append(getUpdateHtml(field, objs[i]));
						sb.append("</td>");
						sb.append("</tr>");
				}
			}else if("2".equals(formColumn)){//如果是两列显示
				int j = 1;
				for (int i = 0; i < fieldList.size(); i++) {
					AutoFormsField field1 = fieldList.get(i);
					//页面是否显示
					if("0".equals(field1.getIsPageShow().toString())){
						columnHidden += "<input type='hidden' id=\""+field1.getFieldName()+"\" name=\""+field1.getFieldName()+"\" value=\""+objs[i]+"\"  />";
						continue;
					}
					if(!field1.getFieldName().equals("ID")){//除了ID的添加
						if(j%2==1){
							sb.append("<tr>");
						}
						//columns += field1.getFieldName() + ",";
						sb.append("<td align=\"right\">"+field1.getCnName()+"：</td>");
						
						//备注合并
						String type = String.valueOf(field1.getPageDisplayType());
						String sfhebing  = String.valueOf(field1.getSfhebing());
						if("3".equals(type)&&"1".equals(sfhebing)&&j%2==1){
							sb.append("<td align=\"left\" colspan=\"3\">");
						}else{
							sb.append("<td align=\"left\">");
						}
						
						//sb.append("<input type=\"text\" id=\""+field1.getFieldName()+"\" name=\""+field1.getFieldName()+"\" value=\""+objs[i]+"\" />");
						if(field1.getFieldName().equals("MEDIA"))
						{
							media=objs[i].toString();
						}
						sb.append(getUpdateHtml(field1, objs[i]));
						sb.append("</td>");
						if(j%2==0){
							sb.append("</tr>");
						}
						j++;
					}
				}  
			}
			sb.append(columnHidden);
			getRequest().setAttribute("columns", columns);
			getRequest().setAttribute("tableContent", sb);
			getRequest().setAttribute("list", list);
			getRequest().setAttribute("formnew", formnew);
			getRequest().setAttribute("fieldList", fieldList);
			getRequest().setAttribute("id", id);
			getRequest().setAttribute("formid",formid);
			getRequest().setAttribute("flowtaskid",flowtaskid);
			return "gotoupdate";
		} catch (Exception e) {
			e.printStackTrace();
			return ERROR;
		}
	}
	public String gotoUpdatepdgs(){
		try {
			/****绑定按钮关联查询需要用的参数  START *****/
			String byTableColumn = getRequest().getParameter("byTableColumn");//外键名称
			String byTableValueId = getRequest().getParameter("byTableValue");
			/****绑定按钮关联查询需要用的参数  END *****/
			String formid = getRequest().getParameter("formid");
			String id = getRequest().getParameter("id");
			 
			String jstj = "";
			String clph = "";
			String[] names = new String[]{"技术条件","材料牌号","上限符号","下限符号","判定规则上限公式","判定规则下限公式","关联项目"};
			String columns = "T_JSTJ,T_CLPH,T_PDSXFH,T_PDXXFH,T_PGSSX,T_PDGSXX,T_PDGS";
			String[] allcolumns = columns.split(",");
			String columnHidden = "";
			StringBuffer sb = new StringBuffer();
			 
			String sql = "select "+columns+" from DIC_ITEM where ID="+id;
			List list = autoService.getDatabySql(sql);//查询所有的数据项
			Object[] objs = null;
			if(list.size()>0){
				objs = (Object[])list.get(0);
			}
			for(int i=0;i<names.length;i++){
				if("技术条件".equals(names[i])){
					jstj = objs[i]!=null?objs[i].toString():"";
				}
				else if("材料牌号".equals(names[i])){
					clph = objs[i]!=null?objs[i].toString():"";
				}
				else{
					sb.append("<tr>");
					sb.append("<td align=\"right\">"+names[i]+"：</td>");
					sb.append("<td align=\"left\">");
					String value = objs[i]!=null?objs[i].toString():"";
					if("关联项目".equals(names[i])){
						String xmname = "";
						if(objs[i]!=null&&!"".equals(objs[i])){
							String querysql = " select  wmsys.wm_concat(t.t_jyxm)  from dic_item t  where t.id in("+value+")";
							List list1 = autoService.getDatabySql(querysql);
							if(null!=list1&&list1.size()>0&&list1.get(0)!=null){
								xmname = list1.get(0).toString();
							}
						}
						sb.append("<input type=\"hidden\" id=\""+allcolumns[i]+"\"   name=\""+allcolumns[i]+"\" value=\""+value+"\">");
						sb.append("<input type=\"text\" readonly=readonly id=\"jyxm\" name=\"jyxm\" value=\""+xmname +"\" style=\"border: 1px solid #999;padding: 5px;width: 200px;\" />");
						sb.append("<img src=\"web/images/form_icon_1.gif\" style=\"cursor:hand; vertical-align: middle;\" onclick=\"selectData('"+jstj+"','"+clph+"')\" />");
						
					}
					else{
						sb.append("<input   type=\"text\"  id=\""+allcolumns[i]+"\" name=\""+allcolumns[i]+"\" value=\""+value+"\" style=\"border: 1px solid #999;padding: 5px;width: 200px;\" />");
					}
					sb.append("</td>");
					sb.append("</tr>");
				}
				
			}
			
			
			sb.append(columnHidden);
			getRequest().setAttribute("columns", columns);
			getRequest().setAttribute("tableContent", sb);
			getRequest().setAttribute("list", list);
			getRequest().setAttribute("formid", formid);
			getRequest().setAttribute("id", id);
			return "updatepdgs";
		} catch (Exception e) {
			e.printStackTrace();
			return ERROR;
		}
	}
	
	/**
	 * 拼接html語句(修改的)
	 * author:lishu	 2013-10-29
	 */
	public String  getUpdateHtml(AutoFormsField field,Object obj){
		StringBuffer sb = new StringBuffer();
		String type = String.valueOf(field.getPageDisplayType());
		String defaultValue = field.getDefaultValue();//獲取默認值
		String eventType = field.getEventType();//事件类型
		String eventName = field.getEventName();//事件名称
		String isReadOnly = field.getIsReadOnly().toString();//页面是否只读（0：否，1：是）
		String readOnlyText = ""; //是否只读 readonly="readonly"
		String event = "";
		if(!StringUtil.isEmpty(eventType)){
			event = eventType + "='" + eventName + "'";
		}
		String bitian = " ";
		String message = "";
		String textLength = "";
		String isreadOnly ="";
		if("NUMBER".equals(field.getFieldType())&&type.equals("0")){
			message = "只允许输入数字";
			bitian += "  class='easyui-numberbox'  missingMessage='"+message+"' ";
			//bitian += "  missingMessage='"+message+"' ";
			
			if("0".equals(type)){
				textLength = "100";
			}
			else if("3".equals(type)){
				textLength = "4000";
			}
		}else{
			if("1".equals(field.getAuthenticationType())){
				message = "必填";
				bitian += " class='easyui-validatebox' ";
			}
			if(!"".equals(field.getFieldLength())){
				if("0".equals(type)){
					textLength =field.getFieldLength()+"";
				}else {
					textLength = field.getFieldLength()+"";
				}
			}else{
				if("0".equals(type)){
					textLength = " 50";
				}
				else{
					textLength = "4000";
				}
			}
		}
		if("1".equals(field.getAuthenticationType())){
			message = "必填";
			bitian += " required missingMessage='"+message+"' ";
		}
		if("1".equals(isReadOnly)){
			readOnlyText = "readonly=readonly";
		}else{
			readOnlyText = "";
		}
		if(field.getIsReadOnly()==1){
			if("2".equals(type)||"4".equals(type)||"5".equals(type)){
				isreadOnly = " disabled ='true' ";
			}else{
				isreadOnly = " readonly = readonly ";
			}
		}
		//页面显示类型（0：文本，1：时间空间，2：下拉菜单，3：文本域,4：单选框，5：复选框，6：操作人，7操作部门，8操作时间）
		if("1".equals(type)){//时间空间
			if("1".equals(isReadOnly)){
				if("null".equals(obj) || obj == null){
					sb.append("<input "+readOnlyText+" type=\"text\" id=\""+field.getFieldName()+"\" name=\""+field.getFieldName()+"\" value=\"\" style=\"border: 1px solid #999;padding: 5px;width: 200px;\"  "+bitian+"/>");
				}else{
					sb.append("<input "+readOnlyText+" type=\"text\" id=\""+field.getFieldName()+"\" name=\""+field.getFieldName()+"\" value=\""+obj+"\" style=\"border: 1px solid #999;padding: 5px;width: 200px;\"  "+bitian+"/>");
				}
			}else{
				if("null".equals(obj) || obj == null){
					sb.append("<input "+readOnlyText+" type=\"text\" id=\""+field.getFieldName()+"\" onClick=\"WdatePicker()\" name=\""+field.getFieldName()+"\" value=\"\" style=\"border: 1px solid #999;padding: 5px;width: 200px;\"  "+bitian+"/>");
				}else{
					sb.append("<input "+readOnlyText+" type=\"text\" id=\""+field.getFieldName()+"\" onClick=\"WdatePicker()\" name=\""+field.getFieldName()+"\" value=\""+obj+"\" style=\"border: 1px solid #999;padding: 5px;width: 200px;\"  "+bitian+"/>");
				}
			}
		}else if("2".equals(type)){//下拉菜单
			if(!StringUtil.isEmpty(defaultValue)){
				String[] values = defaultValue.split(",");
				if("1".equals(isReadOnly)){
					sb.append("<select id=\""+field.getFieldName()+"\" disabled style=\"border: 1px solid #999;padding: 5px;width: 262px;\"  name=\""+field.getFieldName()+"\" "+ event +" "+bitian+">");
				}else{
					sb.append("<select id=\""+field.getFieldName()+"\" style=\"border: 1px solid #999;padding: 5px;width: 262px;\"  name=\""+field.getFieldName()+"\" "+ event +" "+bitian+">");
				}
				for(String value : values){
					if(value.equals(String.valueOf(obj))){
						sb.append("<option value=\""+value+"\" selected=selected>"+value+"</option>");
					}else{
						sb.append("<option value=\""+value+"\" >"+value+"</option>");
					}
				}
				sb.append("</select>");
			}
		}else if("3".equals(type)){//文本域
			String value = "";
			if(!"null".equals(obj)&&obj != null){
				value = obj.toString();
			}
			String sfhebing  = String.valueOf(field.getSfhebing()); //列是否合并
		     if("0".equals(sfhebing)){
		    	 sb.append("<textarea "+readOnlyText+" rows=\"8\" cols=\"31\" id=\""+field.getFieldName()+"\" name=\""+field.getFieldName()+"\" style=\"border: 1px solid #999;padding: 5px;width: 200px;\" "+bitian+">"+value+"</textarea>");
		     }else{
		    	 sb.append("<textarea "+readOnlyText+" rows=\"8\" cols=\"31\" id=\""+field.getFieldName()+"\" name=\""+field.getFieldName()+"\" style=\"border: 1px solid #999;padding: 5px;width: 675px;\" "+bitian+">"+value+"</textarea>");
		     }
		}else if("4".equals(type)){//单选框
			if(!StringUtil.isEmpty(defaultValue)){
				String[] values = defaultValue.split(",");
				String str="";
				for(int i = 0; i < values.length; i++){
					if(i==values.length-1&&"1".equals(field.getAuthenticationType())){
						str=" class='easyui-validatebox' validType=\"radio['pageFrom','"+field.getFieldName()+"']\"";
					}
					if(obj!=null && values[i].equals(obj)){
						sb.append("<input type=\"radio\" style=\"border:none;width:20px; padding-left:0;height:auto;line-height:auto;\" checked=\"checked\" name=\""+field.getFieldName()+"\" value=\""+values[i]+"\""+isreadOnly+str+">" + values[i]);
					}else{
						sb.append("<input type=\"radio\" style=\"border:none;width:20px; padding-left:0;height:auto;line-height:auto;\" name=\""+field.getFieldName()+"\" value=\""+values[i]+"\""+isreadOnly+str+">" + values[i]);
					}
				}
			}
		}else if("5".equals(type)){//复选框
			if(!StringUtil.isEmpty(defaultValue)){
				String[] values = defaultValue.split(",");
				int j = 0;
				String str="";
				for (int i = 0; i < values.length; i++) {
					if(i==values.length-1&&"1".equals(field.getAuthenticationType())){
						str =" class='easyui-validatebox' validType=\"checkbox['pageFrom','"+field.getFieldName()+"']\"";
					}
					String realValue = ","+String.valueOf(obj)+",";
					if(obj!=null && realValue.contains(values[i])){
						sb.append("<input type=\"checkbox\" checked=\"checked\" style=\"border:none;width:20px; padding-left:0;height:auto;line-height:auto;\" name=\""+field.getFieldName()+"\" value=\""+values[i]+"\""+isreadOnly+str+">" + values[i]);
					}else{
						sb.append("<input type=\"checkbox\" style=\"border:none;width:20px; padding-left:0;height:auto;line-height:auto;\" name=\""+field.getFieldName()+"\" value=\""+values[i]+"\""+isreadOnly+str+">" + values[i]);
					}
					if(j%MOD_CHECK==1){
						sb.append("<br/>");
					}
					j++;
				}
			}
		}else if("6".equals(type)){//操作人
			if("null".equals(obj) || obj == null){
				sb.append("<input type=\"text\" readonly=readonly id=\""+field.getFieldName()+"\" name=\""+field.getFieldName()+"\" value=\""+getUserNM()+"\" class=\"tab_input\"/>");
			}else{
				sb.append("<input type=\"text\" readonly=readonly id=\""+field.getFieldName()+"\" name=\""+field.getFieldName()+"\" value=\""+obj+"\" class=\"tab_input\"/>");
			}
			
		}else if("7".equals(type)){//操作部门
			if("null".equals(obj) || obj == null){
				sb.append("<input type=\"text\" readonly=readonly id=\""+field.getFieldName()+"\" name=\""+field.getFieldName()+"\" value=\""+getDeptName()+"\" class=\"tab_input\"/>");
			}else{
				sb.append("<input type=\"text\" readonly=readonly id=\""+field.getFieldName()+"\" name=\""+field.getFieldName()+"\" value=\""+obj+"\" class=\"tab_input\"/>");
			}
		}else if("8".equals(type)){//操作时间
			if("null".equals(obj) || obj == null){
				sb.append("<input type=\"text\" readonly=readonly id=\""+field.getFieldName()+"\" name=\""+field.getFieldName()+"\" value=\""+DateUtilsAll.dateToString(new Date())+"\" class=\"tab_input\"/>");
			}else{
				sb.append("<input type=\"text\" readonly=readonly id=\""+field.getFieldName()+"\" name=\""+field.getFieldName()+"\" value=\""+obj+"\" class=\"tab_input\"/>");
			}
		}else if("9".equals(type)){//操作日期
			if("null".equals(obj) || obj == null){
				sb.append("<input type=\"text\" readonly=readonly id=\""+field.getFieldName()+"\" name=\""+field.getFieldName()+"\" value=\""+DateUtilsAll.dateToStringShort(new Date())+"\" class=\"tab_input\"/>");
			}else{
				sb.append("<input type=\"text\" readonly=readonly id=\""+field.getFieldName()+"\" name=\""+field.getFieldName()+"\" value=\""+obj+"\" class=\"tab_input\"/>");
			}
		}else if("10".equals(type)){//选择部门
			//根据部门id去查询部门名称显示表单上
			String sqlDept = "select t.org_id,t.org_name from sys_organization t where t.org_id ="+obj;
			List listDept = autoService.getDatabySql(sqlDept);//查询所有的数据项
			Object[] objDept = null;
			if(listDept != null && listDept.size() != 0){
				objDept = (Object [])listDept.get(0);
				sb.append("<input type=\"hidden\" id=\""+field.getFieldName()+"\" name=\""+field.getFieldName()+"\" "+bitian+" value=\""+objDept[0]+"\">");
				sb.append("<input type=\"text\" readonly=readonly id=\"dept_"+field.getFieldName()+"\" name=\"dept_"+field.getFieldName()+"\" value=\""+objDept[1]+"\" style=\"border: 1px solid #999;padding: 5px;width: 200px;\" />");
			}else{
				sb.append("<input type=\"hidden\" id=\""+field.getFieldName()+"\" "+bitian+" name=\""+field.getFieldName()+"\">");
				sb.append("<input type=\"text\" readonly=readonly id=\"dept_"+field.getFieldName()+"\" name=\"dept_"+field.getFieldName()+"\" style=\"border: 1px solid #999;padding: 5px;width: 200px;\" />");
			}
			if("1".equals(field.getAuthenticationType())){
				sb.append("<img src=\"images/xh.png\" align=\"absmiddle\"></img>");
			}
			sb.append("<img src=\"web/images/form_icon_1.gif\" style=\"cursor:hand; vertical-align: middle;\" onclick=\"selectdept('"+field.getFieldName()+"')\" />");
		//}else if("11".equals(type)){//选择人员
			//根据人员id查询人员姓名显示表单上
		//	String sqlPerson = "select t.userid,t.username from sys_users t where t.userid="+obj;
		//	List listPerson = autoService.getDatabySql(sqlPerson);//查询所有的数据项
		//	Object[] objPerson = null;
		//	if(listPerson != null && listPerson.size() != 0){
		//		objPerson = (Object [])listPerson.get(0);
		//		sb.append("<input type=\"hidden\" id=\""+field.getFieldName()+"\" "+bitian+" name=\""+field.getFieldName()+"\" value=\""+objPerson[0]+"\">");
		//		sb.append("<input type=\"text\" readonly=readonly id=\"user_"+field.getFieldName()+"\" name=\"user_"+field.getFieldName()+"\" value=\""+objPerson[1]+"\" style=\"border: 1px solid #999;padding: 5px;width: 200px;\" />");
		//	}else{
		//		sb.append("<input type=\"hidden\" id=\""+field.getFieldName()+"\" "+bitian+" name=\""+field.getFieldName()+"\">");
		//		sb.append("<input type=\"text\" readonly=readonly id=\"user_"+field.getFieldName()+"\" name=\"user_"+field.getFieldName()+"\" style=\"border: 1px solid #999;padding: 5px;width: 200px;\" />");
		//	}
		//	sb.append("<img src=\"web/images/form_icon_1.gif\" style=\"cursor:hand; vertical-align: middle;\" onclick=\"selectperson('"+field.getFieldName()+"')\" />");
		}
		else if("11".equals(type)){//选择人员
			//根据人员id查询人员姓名显示表单上
			if(obj!=null && !"".equals(obj) ){
				 	String sqlPerson = "select t.username from sys_users t where t.userid="+obj;
				    List listPerson = autoService.getDatabySql(sqlPerson);//查询所有的数据项
				    String username="";
				 	if(listPerson != null && listPerson.size() != 0&&null!=listPerson.get(0)){
				 		username = listPerson.get(0).toString();
				 	}
				 	sb.append("<input type=\"hidden\" id=\""+field.getFieldName()+"\"  name=\""+field.getFieldName()+"\" value=\""+obj+"\">");
					sb.append("<input type=\"text\" readonly=readonly id=\"user_"+field.getFieldName()+"\" "+bitian+" name=\"user_"+field.getFieldName()+"\" value=\""+username+"\"  "+bitian+"  style=\"border: 1px solid #999;padding: 5px;width: 200px;\"/>");
				sb.append("<img src=\"web/images/form_icon_1.gif\" style=\"cursor:hand; vertical-align: middle;\" onclick=\"selectperson('"+field.getFieldName()+"')\" />");
			}else{

				sb.append("<input type=\"hidden\" id=\""+field.getFieldName()+"\"  name=\""+field.getFieldName()+"\">");
				sb.append("<input type=\"text\" readonly=readonly id=\"user_"+field.getFieldName()+"\" "+bitian+" name=\"user_"+field.getFieldName()+"\" style=\"border: 1px solid #999;padding: 5px;width: 200px;\" value=\"\" />");
				if("1".equals(field.getAuthenticationType())){
					sb.append("<img src=\"images/xh.png\" align=\"absmiddle\"></img>");
				}
				sb.append("<img src=\"web/images/form_icon_1.gif\" style=\"cursor:hand; vertical-align: middle;\" onclick=\"selectperson('"+field.getFieldName()+"')\" />");
			}
		}else if("13".equals(type)){//文件上传
			sb.append("<a href='auto!toUploadcontrol.action?fileid="+obj+"' target='_blank'>文件上传</a>");
			sb.append("<input type=\"hidden\"  id=\""+field.getFieldName()+"\" name=\""+field.getFieldName()+"\" class=\"button_b\" value='"+obj+"' />");
		}
		else if(!StringUtil.isEmpty(field.getForeignTableName())){//如果不满足上述条件  则判断外键是否存在
			//根据外键去查询外键表的id和显示值
			/*String sqlForeign = "select "+field.getForeignCloumn()+","+field.getForeignDisCloumn()+" from "+field.getForeignTableName()+" where TYPENAME = '"+obj+"'";			
			List listForeign = autoService.getDatabySql(sqlForeign);//查询所有的数据项
			Object[] objForeign = null;
			if(listForeign != null && listForeign.size() != 0){
				objForeign = (Object [])listForeign.get(0);
				sb.append("<input type=\"text\" readonly=readonly id=\""+field.getFieldName()+"\" "+bitian+" name=\""+field.getFieldName()+"\" value=\""+objForeign[1]+"\" style=\"border: 1px solid #999;padding: 5px;width: 200px;\" />");
			}else{
			sb.append("<input type=\"text\" readonly=readonly id=\""+field.getFieldName()+"\" "+bitian+" name=\""+field.getFieldName()+"\" style=\"border: 1px solid #999;padding: 5px;width: 200px;\" />");				
			}*/
			if("ID".equals(field.getFieldName())){//如果是主键则隐藏
				sb.append("<input type=\"hidden\" id=\""+field.getFieldName()+"\" name=\""+field.getFieldName()+"\" value=\""+obj+"\" />");
			}else{
				
				
				if("null".equals(obj) || obj == null){
					sb.append("<input "+readOnlyText+" type=\"text\" "+ event +" id=\""+field.getFieldName()+"\" name=\""+field.getFieldName()+"\" value=\"\" "+bitian+"  style=\"border: 1px solid #999;padding: 5px;width: 200px;\"/>");
				}else{
					sb.append("<input "+readOnlyText+" type=\"text\" "+ event +" id=\""+field.getFieldName()+"\" name=\""+field.getFieldName()+"\" value=\""+obj+"\" "+bitian+" data-options=\"min:0,precision:8\" style=\"border: 1px solid #999;padding: 5px;width: 200px;\"/>");
				}
				if("1".equals(field.getAuthenticationType())){
					sb.append("<img src=\"images/xh.png\" align=\"absmiddle\"></img>");
				}
			}
			sb.append("<img src=\"web/images/form_icon_1.gif\" style=\"cursor:hand; vertical-align: middle;\" onclick=\"selectData('"+field.getFieldName()+"','"+field.getForeignTableName()+"','"+field.getForeignCloumn()+"','"+field.getForeignDisCloumn()+"','"+field.getCnName()+"','"+field.getDefaultValue()+"','"+getRequest().getParameter("formid")+"')\" />");
		
		
		
		}
		else if("19".equals(type)){//编号规则
			if(obj==null || "".equals(obj)){
				String no = autoFormService.queryCunstomNumber(field.getCustomNum(), field.getCustomId());
				sb.append("<input type=\"text\" class='finput' readonly=readonly id=\""+field.getFieldName()+"\" name=\""+field.getFieldName()+"\" value=\""+no+"\" "+bitian+" style=\"border: 1px solid #999;padding: 5px;width: 200px;\"/>");
			}else{
				sb.append("<input type=\"text\"   id=\""+field.getFieldName()+"\"  name=\""+field.getFieldName()+"\" value=\""+obj+"\" readonly=\"readonly\" "+bitian+" style=\"border: 1px solid #999;padding: 5px;width: 200px;\"/>");
			}
			
		}else if("20".equals(type)){//试验编号
			if(obj==null || "".equals(obj)){
				sb.append("<input type=\"text\"   id=\""+field.getFieldName()+"\"  name=\""+field.getFieldName()+"\" readonly=\"readonly\" "+bitian+" style=\"border: 1px solid #999;padding: 5px;width: 200px;\"/>");
				sb.append("<input type=\"hidden\"   id=\"TEST_ID\"  name=\"TEST_ID\"  style=\"border: 1px solid #999;padding: 5px;width: 200px;\"/>");
				sb.append("<img src=\"web/images/form_icon_1.gif\" width=\"23\" height=\"23\" border=\"0\" onclick=\"chooseCustomNo('"+field.getFieldName()+"');\" title=\"选择\" style=\"margin-bottom:-6px;cursor:hand;\" />");
				
			}else{
				sb.append("<input type=\"text\"   id=\""+field.getFieldName()+"\"  name=\""+field.getFieldName()+"\" value=\""+obj+"\" readonly=\"readonly\"  "+bitian+" style=\"border: 1px solid #999;padding: 5px;width: 200px;\"/>");
				sb.append("<img src=\"web/images/form_icon_1.gif\" width=\"23\" height=\"23\" border=\"0\" onclick=\"chooseCustomNo('"+field.getFieldName()+"');\" title=\"选择\" style=\"margin-bottom:-6px;cursor:hand;\" />");
			}
		}else{
			if("ID".equals(field.getFieldName())){//如果是主键则隐藏
				sb.append("<input type=\"hidden\" id=\""+field.getFieldName()+"\" name=\""+field.getFieldName()+"\" value=\""+obj+"\" />");
			}else{
				if("null".equals(obj) || obj == null){
					sb.append("<input "+readOnlyText+" type=\"text\" "+ event +" id=\""+field.getFieldName()+"\" name=\""+field.getFieldName()+"\" value=\"\" "+bitian+"  style=\"border: 1px solid #999;padding: 5px;width: 200px;\"/>");
				}else{
					sb.append("<input "+readOnlyText+" type=\"text\" "+ event +" id=\""+field.getFieldName()+"\" name=\""+field.getFieldName()+"\" value=\""+obj+"\" "+bitian+" data-options=\"min:0,precision:8\" style=\"border: 1px solid #999;padding: 5px;width: 200px;\"/>");
				}
			}
		}
		if("1".equals(field.getAuthenticationType())&&(!"10".equals(type)&&!"11".equals(type)&&StringUtil.isEmpty(field.getForeignTableName()))){
			sb.append("<img src=\"images/xh.png\" align=\"absmiddle\"></img>");
		}
		return sb.toString();
	}
	
	/**
	 * 拼接html語句(查看的)
	 * author:lishu	 2013-10-29
	 */
	public String  getViewHtml(AutoFormsField field,Object obj){
		StringBuffer sb = new StringBuffer();
		String type = String.valueOf(field.getPageDisplayType());
		String defaultValue = field.getDefaultValue();//獲取默認值
		String eventType = field.getEventType();//事件类型
		String eventName = field.getEventName();//事件名称
		String isreadOnly = "";//页面是否只读（0：否，1：是）
		String readOnlyText = ""; //是否只读 readonly="readonly"
		String event = "";
		if(!StringUtil.isEmpty(eventType)){
			event = eventType + "='" + eventName + "'";
		}
		String bitian = " ";
		String message = "";
		String textLength = "";
		if(field.getIsReadOnly()==1){
			if("2".equals(type)||"4".equals(type)||"5".equals(type)){
				isreadOnly = " disabled ='true' ";
			}else{
				isreadOnly = " readonly = readonly ";
			}
		}
		if("NUMBER".equals(field.getFieldType())){
			message = "只允许输入数字";
			bitian += "  class='easyui-numberbox'  missingMessage='"+message+"' ";
			if("0".equals(type)){
				textLength = "100";
			}
			else if("3".equals(type)){
				textLength = "4000";
			}
		}else{
			if("1".equals(field.getAuthenticationType())){
				message = "必填";
				bitian += " class='easyui-validatebox' ";
			}
			if(!"".equals(field.getFieldLength())){
				if("0".equals(type)){
					textLength =field.getFieldLength()+"";
				}else {
					textLength = field.getFieldLength()+"";
				}
			}else{
				if("0".equals(type)){
					textLength = " 50";
				}
				else{
					textLength = "4000";
				}
			}
		}
		if("1".equals(field.getAuthenticationType())){
			message = "必填";
			bitian += " required missingMessage='"+message+"' ";
		}
		if(field.getIsReadOnly()==1){
			if("2".equals(type)||"4".equals(type)||"5".equals(type)){
				isreadOnly = " disabled ='true' ";
			}else{
				isreadOnly = " readonly = readonly ";
			}
		}
		
		//页面显示类型（0：文本，1：时间空间，2：下拉菜单，3：文本域,4：单选框，5：复选框，6：操作人，7操作部门，8操作时间）
		if("1".equals(type)){//时间空间
			if("null"==obj||null==obj){
				sb.append("<input type=\"text\" readonly=readonly id=\""+field.getFieldName()+"\"  name=\""+field.getFieldName()+"\" value=\"\" readonly=\"readonly\" style=\"border: 1px solid #999;padding: 5px;width: 200px;\" />");
			}
			else{
				sb.append("<input type=\"text\" readonly=readonly id=\""+field.getFieldName()+"\"  name=\""+field.getFieldName()+"\" value=\""+obj+"\" readonly=\"readonly\"  style=\"border: 1px solid #999;padding: 5px;width: 200px;\" />");
			}
		}else if("2".equals(type)){//下拉菜单
			if(!StringUtil.isEmpty(defaultValue)){
				String[] values = defaultValue.split(",");
				sb.append("<select id=\""+field.getFieldName()+"\" name=\""+field.getFieldName()+"\""+isreadOnly+" style=\"border: 1px solid #999;padding: 5px;width: 200px;\" >");
				for(String value : values){
					if(value.equals(String.valueOf(obj))){
						sb.append("<option value=\""+value+"\" selected=selected>"+value+"</option>");
					}else{
						sb.append("<option value=\""+value+"\" >"+value+"</option>");
					}
				}
				sb.append("</select>");
			}
		}else if("3".equals(type)){//文本域
			String value = "";
			if(!"null".equals(obj)&&obj != null){
				value = obj.toString();
			}
			String sfhebing  = String.valueOf(field.getSfhebing()); //列是否合并
		     if("0".equals(sfhebing)){
		    	 sb.append("<textarea "+readOnlyText+" rows=\"8\" cols=\"31\" id=\""+field.getFieldName()+"\" name=\""+field.getFieldName()+"\" style=\"border: 1px solid #999;padding: 5px;width: 200px;\" "+bitian+">"+value+"</textarea>");
		     }else{
		    	 sb.append("<textarea "+readOnlyText+" rows=\"8\" cols=\"31\" id=\""+field.getFieldName()+"\" name=\""+field.getFieldName()+"\" style=\"border: 1px solid #999;padding: 5px;width: 675px;\" "+bitian+">"+value+"</textarea>");
		     }
		}else if("4".equals(type)){//单选框
			if(!StringUtil.isEmpty(defaultValue)){
				String[] values = defaultValue.split(",");
				String str="";
				for(int i = 0; i < values.length; i++){
					if(i==values.length-1&&"1".equals(field.getAuthenticationType())){
						str=" class='easyui-validatebox' validType=\"radio['pageFrom','"+field.getFieldName()+"']\"";
					}
					if(obj!=null && values[i].equals(obj)){
						sb.append("<input disabled type=\"radio\" style=\"border:none;width:20px; padding-left:0;height:auto;line-height:auto;\" checked=\"checked\" name=\""+field.getFieldName()+"\" value=\""+values[i]+"\""+isreadOnly+str+">" + values[i]);
					}else{
						sb.append("<input disabled type=\"radio\" style=\"border:none;width:20px; padding-left:0;height:auto;line-height:auto;\" name=\""+field.getFieldName()+"\" value=\""+values[i]+"\""+isreadOnly+str+">" + values[i]);
					}
				}
			}
		}else if("5".equals(type)){//复选框
			if(!StringUtil.isEmpty(defaultValue)){
				String[] values = defaultValue.split(",");
				int j = 0;
				String str="";
				for (int i = 0; i < values.length; i++) {
					if(i==values.length-1&&"1".equals(field.getAuthenticationType())){
						str =" class='easyui-validatebox' validType=\"checkbox['pageFrom','"+field.getFieldName()+"']\"";
					}
					String realValue = ","+String.valueOf(obj)+",";
					if(obj!=null && realValue.contains(values[i])){
						sb.append("<input disabled type=\"checkbox\" checked=\"checked\" style=\"border:none;width:20px; padding-left:0;height:auto;line-height:auto;\" name=\""+field.getFieldName()+"\" value=\""+values[i]+"\""+isreadOnly+str+">" + values[i]);
					}else{
						sb.append("<input disabled type=\"checkbox\" style=\"border:none;width:20px; padding-left:0;height:auto;line-height:auto;\" name=\""+field.getFieldName()+"\" value=\""+values[i]+"\""+isreadOnly+str+">" + values[i]);
					}
					if(j%MOD_CHECK==1){
						sb.append("<br/>");
					}
					j++;
				}
			}
		}else if("6".equals(type)){//操作人
			if("null".equals(obj) || obj == null){
				sb.append("<input type=\"text\" readonly=readonly id=\""+field.getFieldName()+"\" name=\""+field.getFieldName()+"\" value=\""+getUserNM()+"\" class=\"tab_input\"/>");
			}else{
				sb.append("<input type=\"text\" readonly=readonly id=\""+field.getFieldName()+"\" name=\""+field.getFieldName()+"\" value=\""+obj+"\" class=\"tab_input\"/>");
			}
			
		}else if("7".equals(type)){//操作部门
			if("null".equals(obj) || obj == null){
				sb.append("<input type=\"text\" readonly=readonly id=\""+field.getFieldName()+"\" name=\""+field.getFieldName()+"\" value=\""+getDeptName()+"\" class=\"tab_input\"/>");
			}else{
				sb.append("<input type=\"text\" readonly=readonly id=\""+field.getFieldName()+"\" name=\""+field.getFieldName()+"\" value=\""+obj+"\" class=\"tab_input\"/>");
			}
		}else if("8".equals(type)){//操作时间
			if("null".equals(obj) || obj == null){
				sb.append("<input type=\"text\" readonly=readonly id=\""+field.getFieldName()+"\" name=\""+field.getFieldName()+"\" value=\""+DateUtilsAll.dateToString(new Date())+"\" class=\"tab_input\"/>");
			}else{
				sb.append("<input type=\"text\" readonly=readonly id=\""+field.getFieldName()+"\" name=\""+field.getFieldName()+"\" value=\""+obj+"\" class=\"tab_input\"/>");
			}
		}else if("9".equals(type)){//操作日期
			if("null".equals(obj) || obj == null){
				sb.append("<input type=\"text\" readonly=readonly id=\""+field.getFieldName()+"\" name=\""+field.getFieldName()+"\" value=\""+DateUtilsAll.dateToStringShort(new Date())+"\" class=\"tab_input\"/>");
			}else{
				sb.append("<input type=\"text\" readonly=readonly id=\""+field.getFieldName()+"\" name=\""+field.getFieldName()+"\" value=\""+obj+"\" class=\"tab_input\"/>");
			}
		}else if("10".equals(type)){//选择部门
			//根据部门id去查询部门名称显示表单上
			String sqlDept = "select t.org_id,t.org_name from sys_organization t where t.org_id ="+obj;
			List listDept = autoService.getDatabySql(sqlDept);//查询所有的数据项
			Object[] objDept = null;
			if(listDept != null && listDept.size() != 0){
				objDept = (Object [])listDept.get(0);
				sb.append("<input type=\"hidden\" id=\""+field.getFieldName()+"\" name=\""+field.getFieldName()+"\"  value=\""+objDept[0]+"\">");
				sb.append("<input type=\"text\" readonly=readonly id=\"dept_"+field.getFieldName()+"\" name=\"dept_"+field.getFieldName()+"\" value=\""+objDept[1]+"\" style=\"border: 1px solid #999;padding: 5px;width: 200px;\" />");
			}else{
				sb.append("<input type=\"hidden\" id=\""+field.getFieldName()+"\" name=\""+field.getFieldName()+"\">");
				sb.append("<input type=\"text\" readonly=readonly id=\"dept_"+field.getFieldName()+"\" name=\"dept_"+field.getFieldName()+"\" style=\"border: 1px solid #999;padding: 5px;width: 200px;\" />");
			}
		}else if("11".equals(type)){//选择人员
			//根据人员id查询人员姓名显示表单上
			String sqlPerson = "select t.userid,t.username from sys_users t where t.userid="+obj;
			List listPerson = autoService.getDatabySql(sqlPerson);//查询所有的数据项
			Object[] objPerson = null;
			if(listPerson != null && listPerson.size() != 0){
				objPerson = (Object [])listPerson.get(0);
				sb.append("<input type=\"hidden\" id=\""+field.getFieldName()+"\" name=\""+field.getFieldName()+"\" value=\""+objPerson[0]+"\">");
				sb.append("<input type=\"text\" readonly=readonly id=\"user_"+field.getFieldName()+"\" name=\"user_"+field.getFieldName()+"\" value=\""+objPerson[1]+"\" style=\"border: 1px solid #999;padding: 5px;width: 200px;\" />");
			}else{
				sb.append("<input type=\"hidden\" id=\""+field.getFieldName()+"\" name=\""+field.getFieldName()+"\">");
				sb.append("<input type=\"text\" readonly=readonly id=\"user_"+field.getFieldName()+"\" name=\"user_"+field.getFieldName()+"\" style=\"border: 1px solid #999;padding: 5px;width: 200px;\" />");
			}
		}else if("13".equals(type)){//文件上传
			sb.append("<a href='auto!toUploadcontrol.action?fileid="+obj+"' target='_blank'>文件上传</a>");
		}else if(!StringUtil.isEmpty(field.getForeignTableName())){//如果不满足上述条件  则判断外键是否存在
			//根据外键去查询外键表的id和显示值
			//String sqlForeign = "select "+field.getForeignCloumn()+","+field.getForeignDisCloumn()+" from "+field.getForeignTableName()+" where ID = "+obj;
			/*String sqlForeign = "select "+field.getForeignCloumn()+","+field.getForeignDisCloumn()+" from "+field.getForeignTableName()+" where TYPENAME = '"+obj+"'";			
			List listForeign = autoService.getDatabySql(sqlForeign);//查询所有的数据项
			Object[] objForeign = null;
			if(listForeign != null && listForeign.size() != 0){
				objForeign = (Object [])listForeign.get(0);
				//sb.append("<input type=\"hidden\" id=\""+field.getFieldName()+"\" name=\""+field.getFieldName()+"\" value=\""+objForeign[0]+"\">");
				//sb.append("<input type=\"text\" readonly=readonly id=\"data_"+field.getFieldName()+"\" name=\"data_"+field.getFieldName()+"\" value=\""+objForeign[1]+"\" style=\"border: 1px solid #999;padding: 5px;width: 200px;\" />");
				sb.append("<input type=\"text\" readonly=readonly id=\""+field.getFieldName()+"\" "+bitian+" name=\""+field.getFieldName()+"\" value=\""+objForeign[1]+"\" style=\"border: 1px solid #999;padding: 5px;width: 200px;\" />");
				
			}else{
				//sb.append("<input type=\"hidden\" id=\""+field.getFieldName()+"\" name=\""+field.getFieldName()+"\">");
				//sb.append("<input type=\"text\" readonly=readonly id=\"data_"+field.getFieldName()+"\" name=\"data_"+field.getFieldName()+"\" style=\"border: 1px solid #999;padding: 5px;width: 200px;\" />");
				sb.append("<input type=\"text\" readonly=readonly id=\""+field.getFieldName()+"\" "+bitian+" name=\""+field.getFieldName()+"\" style=\"border: 1px solid #999;padding: 5px;width: 200px;\" />");				
			}*/
			
			if("ID".equals(field.getFieldName())){//如果是主键则隐藏
				sb.append("<input type=\"hidden\" id=\""+field.getFieldName()+"\" name=\""+field.getFieldName()+"\" value=\""+obj+"\" />");
			}else{
				if("null".equals(obj) || obj == null){
					sb.append("<input "+readOnlyText+" type=\"text\" "+ event +" id=\""+field.getFieldName()+"\" name=\""+field.getFieldName()+"\" value=\"\" "+bitian+"  style=\"border: 1px solid #999;padding: 5px;width: 200px;\"/>");
				}else{
					sb.append("<input "+readOnlyText+" type=\"text\" "+ event +" id=\""+field.getFieldName()+"\" name=\""+field.getFieldName()+"\" value=\""+obj+"\" "+bitian+" data-options=\"min:0,precision:8\" style=\"border: 1px solid #999;padding: 5px;width: 200px;\"/>");
				}
				if("1".equals(field.getAuthenticationType())){
					sb.append("<img src=\"images/xh.png\" align=\"absmiddle\"></img>");
				}
			}
			sb.append("<img src=\"web/images/form_icon_1.gif\" style=\"cursor:hand; vertical-align: middle;\" onclick=\"selectData('"+field.getFieldName()+"','"+field.getForeignTableName()+"','"+field.getForeignCloumn()+"','"+field.getForeignDisCloumn()+"','"+field.getCnName()+"','"+field.getDefaultValue()+"','"+getRequest().getParameter("formid")+"')\" />");
		
		}else{
			if("ID".equals(field.getFieldName())){//如果是主键则隐藏
				sb.append("<input type=\"hidden\" id=\""+field.getFieldName()+"\" name=\""+field.getFieldName()+"\" value=\""+obj+"\" />");
			}else{
				if("null"==obj||null==obj){
					sb.append("<input type=\"text\" id=\""+field.getFieldName()+"\" name=\""+field.getFieldName()+"\" value=\"\" readonly=readonly style=\"border: 1px solid #999;padding: 5px;width: 200px;\" />");
				}
				else{
					sb.append("<input type=\"text\" id=\""+field.getFieldName()+"\" name=\""+field.getFieldName()+"\" value=\""+obj+"\" readonly=readonly style=\"border: 1px solid #999;padding: 5px;width: 200px;\" />");
				}
			}
		}
		return sb.toString();
	}
	
	/**
	 * 更新页面
	 * author:lishu	 2013-10-28 
	 */
	public void updateForm() throws Exception{
		//setContentType();
		PrintWriter out = getResponse().getWriter();
		try {
			String columns = getRequest().getParameter("columns");//页面所有的列
			String formid = getRequest().getParameter("formid");
			String id = getRequest().getParameter("ID");
			String annexIds = "";
			String[] allAnnexId =null;
			String flag = "1";//发动机平台区别号是否存在的标识 
			if(flag.equals("1")){
				//存文件
				List files = getUploadfile();
				if (files!=null)
				{
					for (int i = 0 ; i < files.size() ; i++) 
					{ 
						String fileName = (String) getUploadfileFileName().get(i);
						String fileType = fileName.substring((fileName.lastIndexOf("."))+1, fileName.length());
						File ff = new File(files.get(i).toString());
						if(ff.length()>0)
						{
							ActionContext ac = ActionContext.getContext();
					        ServletContext sc = (ServletContext) ac.get(ServletActionContext.SERVLET_CONTEXT);
					        String url = getRequest().getSession().getAttribute("SYS_FILEPATH").toString();
					        SimpleDateFormat simpleDateFormat =  new SimpleDateFormat("yyyyMM");
						    String date = simpleDateFormat.format(new Date());
						    url = url +"/annex/"+date;
							File file = new File(url);
							if ( ! (file.exists())  &&   ! (file.isDirectory()))  {
				                 boolean  creadok  =  file.mkdirs();
				                 if (creadok)  {
				                    System.out.println( " ok:创建文件夹成功！ " );
				                } else  {
				                    System.out.println( " err:创建文件夹失败！ " );                    
				                } 
				            } 
							String address = url + "/" + getUploadfileFileName().get(i);
							FileOutputStream fos = new FileOutputStream(address); 
							FileInputStream fis = new FileInputStream(files.get(i).toString()); 
							byte[] buffer = new byte[1024]; 
							int len = 0; 
							while ((len = fis.read(buffer)) > 0) 
							{ 
								fos.write(buffer, 0, len);
							} 
							fos.close();
							fis.close();
							//将附件保存到Tdm_annex中
							TdmAnnex annex = new TdmAnnex();
							annex.setFileName(getUploadfileFileName().get(i).toString());
							annex.setFilePath("/annex/"+date+"/" + getUploadfileFileName().get(i));
							annex.setAnnexType(1l);
							annex.setCreateTime(new Date());
							annex.setCreateUserid(Long.parseLong(this.getUserId()));
							annex.setCreateUsername(this.getUserName());
							String annexId = autoService.saveObject(annex);
							annexIds = annexIds +","+annexId;
						}
					}
				}
				if(!"".equals(annexIds)){
					annexIds = annexIds.substring(1);
					allAnnexId = annexIds.split(",");
				}
				//查询表单信息
				AutoFormsNew formnew =  autoFormService.getAutoFormsNewById(formid);
				//取得字段类型是文件的元素
				List fileColumnList = new ArrayList();
				List checkBoxList = new ArrayList();
				List<AutoFormsField> fieldList = autoFormService.getAutoFormsFieldByformid(formid);
				for(int i = 0; i<fieldList.size();i++){
					AutoFormsField aff = fieldList.get(i);
					if(aff.getPageDisplayType()!=null&&"13".equals(aff.getPageDisplayType().toString())){
						fileColumnList.add(aff.getFieldName());
					}else if(aff.getPageDisplayType()!=null&&"5".equals(aff.getPageDisplayType().toString())){
						checkBoxList.add(aff.getFieldName());
					}
					
				}
				String asql = "";//拼接sql语句
				if(columns != null){
					String[] columnss = columns.split(",");
					int fileNameIndex = 0;
					//字段索引
					int fieldIndex=0;
					for(String column : columnss){
						String columnValue = getRequest().getParameter(column);
						
						if(fileColumnList.contains(column)){
							if(uploadfileFileName != null && !"".equals(uploadfileFileName.get(fileNameIndex))){
						//		columnValue = uploadfileFileName.get(fileNameIndex).toString();
								columnValue = allAnnexId[fileNameIndex];
								fileNameIndex++;
							}
						}
						else if(checkBoxList.contains(column)){//如果是复选框
							String[] values = getRequest().getParameterValues(column);
							columnValue=org.apache.commons.lang.StringUtils.join(values,",");
						}else{
							columnValue = getRequest().getParameter(column);
						}
						if(columnValue == null||"null".equals(columnValue)){
						 //	asql += column + "='',";
							columnValue = "";
						}
						if(columnValue == null||"".equals(columnValue)||"null".equals(columnValue)){
							asql += column + "='',";
						}
						else{
							AutoFormsField aff = fieldList.get(fieldIndex);
							if(aff.getFieldType().equals("DATE"))
							{
								asql += column + "=to_date('"+columnValue+"','YYYY/MM/DD'),";		
							}
							else
							{
								asql += column + "='"+columnValue+"',";
							}
							//asql += column + "='"+columnValue+"',";
						}
						fieldIndex++;
					}
					String sql = "update "+formnew.getFormEnName()+" set "+asql.substring(0,asql.length()-1)+" where id="+id;
					autoService.executeSql(sql);
				}
				out.print("{\"result\":\"success\"}");
			}else{
				out.print("{\"result\":\"exist\"}");
			}
		} catch (Exception e) {
			e.printStackTrace();
			out.print("{\"result\":\"error\"}");
		}
	}
	/**
	 * 删除编号规则
	 * @author zhn
	 * @date Jun 26, 2014 10:21:51 AM
	 * @return
	 * @throws IOException 
	 */
	public String deleteCustomNumber() throws IOException{
		setContentType();
		PrintWriter out = getResponse().getWriter();
	  	try {
	  		String id=getRequest().getParameter("id");
			//查询有没有被使用的编号
			String sql1 = "  select count(*) from cf_tdm t where t.test_id=  "+id+"  ";
			List listSeq = autoService.getDatabySql(sql1);
			if(listSeq != null && !listSeq.get(0).toString().equals("0")){
				out.print("{\"result\":\"have\",\"id\":\""+id+"\"}");
			}else{
				//删除
				String sql2 = "  delete from tdm_custom_no t1 where t1.id = "+id+"  ";
				autoService.executeSql(sql2);
				out.print("{\"result\":\"success\"}");
			}
	  	
	  	} catch (Exception e) {
			e.printStackTrace();
			out.print("{\"result\":\"error\"}");
		}
		return null;
	}
	/**
	 * 跳转到查看页面
	 * author:lishu	 2013-10-28
	 */
	public String gotoView(){
		try {
			String formid = getRequest().getParameter("formid");
			String id = getRequest().getParameter("id");
			//查询表单信息
			AutoFormsNew formnew = autoFormService.getAutoFormsNewById(formid);
			//查询字段信息
			List<AutoFormsField> fieldList = autoFormService.getAutoFormsFieldByformid(formid);
			
			String columns = "";
			String columnHidden = "";
			StringBuffer sb = new StringBuffer();
			for(AutoFormsField field : fieldList){
					columns += field.getFieldName() + ",";
			}
			if(columns.length()>0){
				columns = columns.substring(0,columns.length()-1);
			}
			String sql = "select "+columns+" from " + formnew.getFormEnName() + " where ID="+id;
			List list = autoService.getDatabySql(sql);//查询所有的数据项
			Object[] objs = null;
			if(list.size()>0){
				objs = (Object[])list.get(0);
			}
			//拼接页面字段
			String formColumn = String.valueOf(formnew.getFormColumn());
			if("1".equals(formColumn)){//如果是一列显示
				for(int i=0;i<fieldList.size();i++){
					AutoFormsField field = fieldList.get(i);
						//页面是否显示
						if("0".equals(field.getIsPageShow().toString())){
							columnHidden += "<input type='hidden' id=\""+field.getFieldName()+"\" name=\""+field.getFieldName()+"\" value=\""+objs[i]+"\"  />";
							continue;
						}
						sb.append("<tr>");
						if(!"主键".equals(field.getCnName())){
							sb.append("<td align=\"right\">"+field.getCnName()+"：</td>");
						}
						sb.append("<td align=\"left\">");
						//sb.append("<input type=\"text\" id=\""+field.getFieldName()+"\" name=\""+field.getFieldName()+"\" value=\""+objs[i]+"\" />");
						sb.append(getViewHtml(field, objs[i]));
						sb.append("</td>");
						sb.append("</tr>");
				}
			}else if("2".equals(formColumn)){//如果是两列显示
				int j = 1;
				for (int i = 0; i < fieldList.size(); i++) {
					AutoFormsField field1 = fieldList.get(i);
					if(!field1.getFieldName().equals("ID")){//除了ID的添加
						//页面是否显示
						if("0".equals(field1.getIsPageShow().toString())){
							columnHidden += "<input type='hidden' id=\""+field1.getFieldName()+"\" name=\""+field1.getFieldName()+"\" value=\""+objs[i]+"\"  />";
							continue;
						}
						if(j%2==1){
							sb.append("<tr>");
						}
						columns += field1.getFieldName() + ",";
						sb.append("<td align=\"right\">"+field1.getCnName()+"：</td>");
						String type = String.valueOf(field1.getPageDisplayType());
						String sfhebing  = String.valueOf(field1.getSfhebing());
						if("3".equals(type)&&"1".equals(sfhebing)&&j%2==1){
							sb.append("<td align=\"left\" colspan=\"3\">");
						}else{
							sb.append("<td align=\"left\">");
						}
						//sb.append("<input type=\"text\" id=\""+field1.getFieldName()+"\" name=\""+field1.getFieldName()+"\" value=\""+objs[i]+"\" />");
						sb.append(getViewHtml(field1, objs[i]));
						sb.append("</td>");
						if(j%2==0){
							sb.append("</tr>");
						}
						j++;
					}
				}  
			}
			sb.append(columnHidden);
			getRequest().setAttribute("columns", columns);
			getRequest().setAttribute("tableContent", sb);
			getRequest().setAttribute("list", list);
			getRequest().setAttribute("formnew", formnew);
			getRequest().setAttribute("fieldList", fieldList);
			getRequest().setAttribute("formid", formid);
			return "gotoView";
		} catch (Exception e) {
			e.printStackTrace();
			return ERROR;
		}
	}
	
	
	public String gotoAnalysisView(){
		try {
			String tablename = getRequest().getParameter("tableName");
			String filemodeid = getRequest().getParameter("filemodeid");
			String ids = getRequest().getParameter("ids");
			String strSql = "select baseinfoid,datainfoid from file_mode where id="+filemodeid;
			List lists = autoService.getDatabySql(strSql);
			Object[] objs = (Object[])lists.get(0);
			String baseinfoid = objs[0].toString();
			String datainfoid = objs[1].toString();
			
			getRequest().setAttribute("filemodeid", filemodeid);
			getRequest().setAttribute("hengzhou", getAnalysisOption(datainfoid,"VARCHAR2"));
			getRequest().setAttribute("zongzhou", getAnalysisOption(datainfoid,"NUMBER"));
			getRequest().setAttribute("ids", ids);

			return "gotoAnalysisView";
		} catch (Exception e) {
			e.printStackTrace();
			return ERROR;
		}
	}
	
	public String getAnalysisOption(String formid,String type){
		StringBuffer sb = new StringBuffer();
		String strSql = "select field_name,cn_name from auto_forms_field t where t.forms_id='"+formid+"' and " +
				"t.field_name not in ('ID','FLOWTASKID','FILEMODEID') and t.field_type='"+type+"'";
		List lists = autoService.getDatabySql(strSql);
		sb.append("<option value='-1'>请选择</option>");
		for(int i=0;i<lists.size();i++){
			Object[] objs = (Object[])lists.get(i);
			sb.append("<option value='"+objs[0]+"'>"+objs[1]+"</option>");
		}
		return sb.toString();
	}
	
	public String gotoAnalysisPage(){
		try {
			String hengzhou = getRequest().getParameter("hengzhou");
			String zongzhou = getRequest().getParameter("zongzhou");
			String fenzu = getRequest().getParameter("fenzu");
			String juji = getRequest().getParameter("juji");
			String biaozhunz = getRequest().getParameter("biaozhunz");
			String filemodeid = getRequest().getParameter("filemodeid");
			String ids = getRequest().getParameter("ids");
			String strWhere = "";
			if (ids!=null&&!ids.equals("")){
				strWhere = " where flowtaskid in ("+ids+") ";
			}
			
			String strSql = "select baseinfoid,datainfoid from file_mode where id="+filemodeid;
			List lists = autoService.getDatabySql(strSql);
			Object[] objs = (Object[])lists.get(0);
			String baseinfoid = objs[0].toString();
			String datainfoid = objs[1].toString();
			String tablename = getTableName(datainfoid);
			String hengzhouname = getFiledname(datainfoid,hengzhou);
			String zongzhouname = getFiledname(datainfoid,zongzhou);
			StringBuffer graphssb = new StringBuffer();
			StringBuffer biaozhunsb = new StringBuffer();
			JSONArray jsonarray = new JSONArray();
			
			if (fenzu.equals("-1")||fenzu.equals(hengzhou)){
				//GRAPHS
				graphssb.append("var graph = new AmCharts.AmGraph();\n");
				graphssb.append("graph.title = \""+hengzhouname+"\";\n");
				graphssb.append("graph.valueField = \""+zongzhou+"\";\n");
				graphssb.append("graph.balloonText = \"[["+zongzhou+"]]\";\n");
				graphssb.append("graph.lineAlpha = 1;\n");
				graphssb.append("graph.bullet = \"round\";\n");
				graphssb.append("graph.addListener(\"clickGraphItem\", " +
						"function(a) { showdetail(a.item.dataContext.hengzhou);});\n");
				graphssb.append("chart.addGraph(graph);\n");
				
				strSql = "select "+hengzhou+","+getJujigs(juji,zongzhou)+" from "+tablename+strWhere+" group by "+hengzhou;
				List datalist = autoService.getDatabySql(strSql);
				for(int i=0;i<datalist.size();i++){
					Object[] dataobjs = (Object[])datalist.get(i);
					JSONObject jsonobject = new JSONObject();
					jsonobject.put("hengzhou", dataobjs[0].toString());
					jsonobject.put(zongzhou, dataobjs[1].toString());
					jsonarray.add(jsonobject);
				}
			}
			else{
				strSql = "select distinct "+fenzu+" from "+tablename+strWhere+" t order by "+fenzu+"";
				List fenzulist = autoService.getDatabySql(strSql);
				for(int i=0;i<fenzulist.size();i++){
					//GRAPHS
					graphssb.append("var graph = new AmCharts.AmGraph();\n");
					graphssb.append("graph.title = \""+fenzulist.get(i)+"\";\n");
					graphssb.append("graph.valueField = \"field"+i+"\";\n");
					graphssb.append("graph.balloonText = \"[["+zongzhou+"]]\";\n");
					graphssb.append("graph.lineAlpha = 1;\n");
					graphssb.append("graph.bullet = \"round\";\n");
					graphssb.append("graph.addListener(\"clickGraphItem\", " +
					"function(a) { showdetail(a.item.dataContext.hengzhou,a.item.graph.title);});\n");
					graphssb.append("chart.addGraph(graph);\n");
					graphssb.append("\n");
				}
				
				strSql = "select "+hengzhou+" from "+tablename+strWhere+" group by "+hengzhou;
				List datalist = autoService.getDatabySql(strSql);
				for(int i=0;i<datalist.size();i++){
					JSONObject jsonobject = new JSONObject();
					jsonobject.put("hengzhou", datalist.get(i));
					for(int j=0;j<fenzulist.size();j++){
						strSql = "select "+getJujigs(juji,zongzhou)+" from "+tablename+strWhere+" t group by "+hengzhou+","+fenzu+" having "+hengzhou+"='"+datalist.get(i).toString().trim()+"'and "+fenzu+"='"+fenzulist.get(j).toString().trim()+"'";
						List listdata = autoService.getDatabySql(strSql);
						if (listdata.size()>0){
							jsonobject.put("field"+j, listdata.get(0).toString());
						}
						else{
							jsonobject.put("field"+j, 0);
						}
					}
					jsonarray.add(jsonobject);
				}
			}
			
			//GUIDE
			if (!biaozhunz.equals("")){
				biaozhunsb.append("var guide = new AmCharts.Guide();\n");
				biaozhunsb.append("guide.value = "+biaozhunz+";\n");
				biaozhunsb.append("guide.lineColor = \"#CC0000\";\n");
				biaozhunsb.append("guide.dashLength = 4;\n");
				biaozhunsb.append("guide.label = \"标准值\";\n");
				biaozhunsb.append("guide.inside = true;\n");
				biaozhunsb.append("guide.lineAlpha = 1;\n");
				biaozhunsb.append("valueAxis.addGuide(guide);\n");
			}

			this.getRequest().setAttribute("datas", jsonarray.toString());
			this.getRequest().setAttribute("graphssb", graphssb.toString());
			this.getRequest().setAttribute("biaozhunsb", biaozhunsb.toString());
			this.getRequest().setAttribute("hengzhou", hengzhou);
			this.getRequest().setAttribute("zongzhou", zongzhou);
			this.getRequest().setAttribute("hengzhouname", hengzhouname);
			this.getRequest().setAttribute("zongzhouname", zongzhouname);
			this.getRequest().setAttribute("fenzu", fenzu);
			this.getRequest().setAttribute("juji", juji);
			this.getRequest().setAttribute("biaozhunz", biaozhunz);
			this.getRequest().setAttribute("datainfoid", datainfoid);
			
			return "gotoAnalysisPage";
		} catch (Exception e) {
			e.printStackTrace();
			return ERROR;
		}
	}
	
	public String getTableName(String formid){
		String strSql = "select FORM_EN_NAME from auto_forms_new t where t.id="+formid;
		List lists = autoService.getDatabySql(strSql);
		if (lists.size()>0){
			return lists.get(0).toString();
		}
		else{
			return "";
		}
	}
	
	public String getJujigs(String juji,String fieldname){
		if (juji.equals("pingjun")){
			return "round(avg("+fieldname+"),2)";
		}
		else if (juji.equals("qiuhe")){
			return "round(sum("+fieldname+"),2)";
		}
		else{
			return "count("+fieldname+")";
		}
	}
	
	public String getFiledname(String fromid,String filedname){
		String strSql = "select cn_name from auto_forms_field t where t.forms_id='"+fromid+"' and t.field_name='"+filedname+"'";
		List lists = autoService.getDatabySql(strSql);
		if (lists.size()>0){
			return lists.get(0).toString();
		}
		else{
			return "";
		}
	}
	
	
	/**
	 * 进入编号规则修改方法
	 * @author zhn
	 * @date Aug 13, 2014 3:12:00 PM
	 * @throws Exception
	 */
	public String goUpdateCustomNumber() throws Exception{
		setContentType();
		String id = getRequest().getParameter("id");
		tdmCustomNo = autoFormService.goUpdateCustomNumber(id);
		getRequest().setAttribute("id", id);
		return "updateCustom";
	}
	
	/**
	 * 删除数据
	 * @throws Exception
	 */
	public void deleteFormAll() throws Exception{
		setContentType();
		PrintWriter out = getResponse().getWriter();
		try {
			String mainTableId=getRequest().getParameter("formId");
			String tableName = getRequest().getParameter("tableName");
			String sql="";
			//删除附件
			deleteAttachmentAll(tableName);
			String deleteSql = "delete from "+ tableName +" t ";
			autoService.executeSql(deleteSql);
			
			//删除子表对应的数据
			sql="select FORM_EN_NAME,BY_TABLE_COLUMN from auto_forms_button t," +
					"auto_forms_new t1 where t.THIS_TABLE_NAME_ID='"+mainTableId+"' and " +
					"t1.id=t.by_table_name_id";
			 List<Object[]> list=autoService.getDatabySql(sql);
			 String childTableName=null;
			 String childTableField=null;
			 if(list.size()!=0)
			  {	  
				 Object[] data=list.get(0);
				 childTableName=(String) data[0];
				 childTableField=(String) data[1];
				 //删除子表中附件、图片
				 deleteAttachmentAll(childTableName);
				 //删除子表数据
				 sql="delete from "+childTableName;
				 autoService.executeSql(sql);				
			  }			
			 //如果是管线表删除管线节点表相应记录
			 if(tableName.equals("PTEM_PIPELINE"))
			 { 
				sql="delete from PTEM_PIPELINE_NODE t";
				autoService.executeSql(sql);
			 }
			 out.print("{\"result\":\"success\"}");
		} catch (Exception e) {
			e.printStackTrace();
			out.print("{\"result\":\"error\"}");
		}
	}
	
	
	/**
	 * 删除数据
	 * @throws Exception
	 */
//	public void deleteForm() throws Exception{
//		setContentType();
//		PrintWriter out = getResponse().getWriter();
//		try {
//			String mainTableId=getRequest().getParameter("formId");
//			String ids = getRequest().getParameter("ids");
//			String tableName = getRequest().getParameter("tableName");
//			String pipelinenos="";
//			String sql="";
//			if(tableName.equals("PTEM_PIPELINE"))
//			{
//				sql="select pipelineno from PTEM_PIPELINE where id in("+ids+")";
//				List<String> listPipelineno=autoService.getDatabySql(sql);
//				int num=listPipelineno.size();				
//				for(int i=0;i<num;i++)
//				{
//					pipelinenos+="'";
//					pipelinenos+=listPipelineno.get(i);
//					pipelinenos+="'";
//					pipelinenos+=",";
//				}
//				pipelinenos=pipelinenos.substring(0,pipelinenos.length()-1);
//			}
//			
//			String deleteSql = "delete from "+ tableName +" t where t.id in("+ids+")";
//			autoService.executeSql(deleteSql);
//			//删除子表对应的数据
//			sql="select FORM_EN_NAME,BY_TABLE_COLUMN from auto_forms_button t," +
//					"auto_forms_new t1 where t.THIS_TABLE_NAME_ID='"+mainTableId+"' and " +
//					"t1.id=t.by_table_name_id";
//			 List<Object[]> list=autoService.getDatabySql(sql);
//			 String childTableName=null;
//			 String childTableField=null;
//			 if(list.size()!=0)
//			  {	  
//				 Object[] data=list.get(0);
//				 childTableName=(String) data[0];
//				 childTableField=(String) data[1];
//				 sql="delete from "+childTableName+" where "+childTableField+" in("+ids+")";
//				 autoService.executeSql(sql);
//			  }			
//			 //如果是管线表删除管线节点表相应记录
//			 if(tableName.equals("PTEM_PIPELINE"))
//			 { 
//				sql="delete from PTEM_PIPELINE_NODE t where t.pipelineno in("+pipelinenos+")";
//				autoService.executeSql(sql);
//			 }
//			 out.print("{\"result\":\"success\"}");
//		} catch (Exception e) {
//			e.printStackTrace();
//			out.print("{\"result\":\"error\"}");
//		}
//	}
//	
	public void deleteAttachment(String tableName,String ids) throws Exception{
		//删除图片附件记录
		String sql="select t.field_name from AUTO_FORMS_FIELD t where t.PAGE_DISPLAY_TYPE=13 and " +
				"t.FORMS_ID=(select t2.id from AUTO_FORMS_NEW t2 " +
				"where t2.FORM_EN_NAME='"+tableName+"')";
		List<String> listField=autoService.getDatabySql(sql);
		int fieldnum=listField.size();
		List<String> listFielpathAll=new ArrayList();
		for(int i=0;i<fieldnum;i++)
		{
			String fieldname=listField.get(i);
			sql="select t."+fieldname+" from "+tableName+" t where t.id in("+ids+")";
			List<String> listVal=autoService.getDatabySql(sql);
			int num=listVal.size();
			for(int j=0;j<num;j++)
			{
				String value=listVal.get(j);
				sql="select t.file_path from tdm_attachment t where t.code_id="+value;
				List<String> listFilepath=autoService.getDatabySql(sql);
				int filenum=listFilepath.size();
				for(int k=0;k<filenum;k++)
				{					
					String filepath="";
					if(listFilepath.get(k)!=null&&!listFilepath.get(k).equals(""))
					{
						filepath=listFilepath.get(k);
						listFielpathAll.add(filepath);
					}					
				}
				
				sql="delete from tdm_attachment t where t.code_id="+value;
				autoService.executeSql(sql);
				sql="delete from ptem_attachment t where t.code_id="+value;
				autoService.executeSql(sql);
			}
		}
		//删除图片附件
		int numAll=listFielpathAll.size();
		for(int i=0;i<numAll;i++)
		{
			String filepath=listFielpathAll.get(i);
			sql="select * from tdm_attachment t where t.file_path='"+filepath+"'";
			List<String> listFilepath=autoService.getDatabySql(sql);
			if(listFilepath.size()==0)
			{
				String realfilepath="D:\\"+filepath;
				File file = new File(realfilepath);  				
				if (file.exists()&&file.isFile())  
				{
					file.delete();  
					String parent=file.getParent();
					while(parent!=null)
					{
						File fileParent=new File(parent);
						File[] files=fileParent.listFiles();
						if(files!=null&&files.length==0)
						{
							fileParent.delete();
							parent=fileParent.getParent();
						}
						else
						{
							break;
						}
					}				
					
				}				
			}
		}
	}
	public void deleteAttachmentAll(String tableName) throws Exception{
		//删除图片附件记录
		String sql="select t.field_name from AUTO_FORMS_FIELD t where t.PAGE_DISPLAY_TYPE=13 and " +
				"t.FORMS_ID=(select t2.id from AUTO_FORMS_NEW t2 " +
				"where t2.FORM_EN_NAME='"+tableName+"')";
		List<String> listField=autoService.getDatabySql(sql);
		int fieldnum=listField.size();
		List<String> listFielpathAll=new ArrayList();
		for(int i=0;i<fieldnum;i++)
		{
			String fieldname=listField.get(i);
			sql="select t."+fieldname+" from "+tableName+" t ";
			List<String> listVal=autoService.getDatabySql(sql);
			int num=listVal.size();
			for(int j=0;j<num;j++)
			{
				String value=listVal.get(j);
				sql="select t.file_path from tdm_attachment t where t.code_id="+value;
				List<String> listFilepath=autoService.getDatabySql(sql);
				int filenum=listFilepath.size();
				for(int k=0;k<filenum;k++)
				{					
					String filepath="";
					if(listFilepath.get(k)!=null&&!listFilepath.get(k).equals(""))
					{
						filepath=listFilepath.get(k);
						listFielpathAll.add(filepath);
					}					
				}
				
				sql="delete from tdm_attachment t where t.code_id="+value;
				autoService.executeSql(sql);
				sql="delete from ptem_attachment t where t.code_id="+value;
				autoService.executeSql(sql);
			}
		}
		//删除图片附件
		int numAll=listFielpathAll.size();
		for(int i=0;i<numAll;i++)
		{
			String filepath=listFielpathAll.get(i);
			sql="select * from tdm_attachment t where t.file_path='"+filepath+"'";
			List<String> listFilepath=autoService.getDatabySql(sql);
			if(listFilepath.size()==0)
			{
				String realfilepath="D:\\"+filepath;
				File file = new File(realfilepath);  				
				if (file.exists()&&file.isFile())  
				{
					file.delete();  
					String parent=file.getParent();
					while(parent!=null)
					{
						File fileParent=new File(parent);
						File[] files=fileParent.listFiles();
						if(files!=null&&files.length==0)
						{
							fileParent.delete();
							parent=fileParent.getParent();
						}
						else
						{
							break;
						}
					}				
				}				
			}
		}
	}
	public String getchildids(String ids,String tablename) throws IOException {
		String sql="select t.id from "+tablename+" t where t.parentid in("+ids+")";
		List<String> list=autoService.getDatabySql(sql);
		int num=list.size();
		String childids="";
		for(int i=0;i<num;i++)
		{
			childids+=list.get(i);
			childids+=",";
		}
		childids=childids.substring(0,childids.length()-1);
		return childids;
	}
	public void deleteForm() throws Exception{
		setContentType();
		PrintWriter out = getResponse().getWriter();
		try {
			String mainTableId=getRequest().getParameter("formId");
			String ids = getRequest().getParameter("ids");
			String tableName = getRequest().getParameter("tableName");
			String pipelinenos="";
			String sql="";
			if(tableName.equals("PTEM_PIPELINE"))
			{
				sql="select pipelineno from PTEM_PIPELINE where id in("+ids+")";
				List<String> listPipelineno=autoService.getDatabySql(sql);
				int num=listPipelineno.size();				
				for(int i=0;i<num;i++)
				{
					pipelinenos+="'";
					pipelinenos+=listPipelineno.get(i);
					pipelinenos+="'";
					pipelinenos+=",";
				}
				pipelinenos=pipelinenos.substring(0,pipelinenos.length()-1);
			}
			//删除附件、图片
			deleteAttachment(tableName,ids);	
			String deleteSql = "delete from "+ tableName +" t where t.id in("+ids+")";
			autoService.executeSql(deleteSql);
					
			//删除子表对应的数据
			sql="select FORM_EN_NAME,BY_TABLE_COLUMN from auto_forms_button t," +
					"auto_forms_new t1 where t.THIS_TABLE_NAME_ID='"+mainTableId+"' and " +
					"t1.id=t.by_table_name_id";
			 List<Object[]> list=autoService.getDatabySql(sql);
			 String childTableName=null;
			 String childTableField=null;
			 if(list.size()!=0)
			  {	  
				 Object[] data=list.get(0);
				 childTableName=(String) data[0];
				 childTableField=(String) data[1];
				 //删除附件、图片
				 String idschild= getchildids(ids,childTableName);
				 deleteAttachment(childTableName,idschild);
				 sql="delete from "+childTableName+" where "+childTableField+" in("+ids+")";
				 autoService.executeSql(sql);
				
			  }			
			 //如果是管线表删除管线节点表相应记录
			 if(tableName.equals("PTEM_PIPELINE"))
			 { 
				sql="delete from PTEM_PIPELINE_NODE t where t.pipelineno in("+pipelinenos+")";
				autoService.executeSql(sql);
			 }
			 out.print("{\"result\":\"success\"}");
		} catch (Exception e) {
			e.printStackTrace();
			out.print("{\"result\":\"error\"}");
		}
	}
	/**
	 * 选择表单
	 * @return
	 * @throws IOException
	 */
	public String chooseDatalist() throws IOException{
		String media = this.getRequest().getParameter("media");
		String tablename = this.getRequest().getParameter("tablename");
		String colname = this.getRequest().getParameter("colname");
		String disname = this.getRequest().getParameter("disname");
		String cnname = this.getRequest().getParameter("cnname");
		String flowid = getRequest().getParameter("flowid");
		String fileColname = this.getRequest().getParameter("fileColname");
		String formid = this.getRequest().getParameter("formid");
		String fileName = this.getRequest().getParameter("fileName");
		String byTableValueId = this.getRequest().getParameter("byTableValueId");
		String unittype = this.getRequest().getParameter("unittype");
		
		if(tablename.equals("SYS_ORGANIZATION"))
		{
			colname= "ORG_ID";
		}
		else if(tablename.equals("SYS_USERS"))
		{
			colname= "USERID";
		}
		else
		{
			colname= "ID";
		}
		
		String disnameshow = "";		
		//String disnameshow1 = "{'ID':'\"+row."+colname+"+\"'";
		String headershow = "";
		//headershow+="'ID'";
		String[] disnamearray = disname.split(",");
		String disnameshow1 = "{'ID':'\"+row."+disnamearray[0]+"+\"'";
		String tableIdSql = "select t.id from auto_forms_new t where t.form_en_name = '"+tablename+"'";
		List tableList = autoFormService.getDatabySql(tableIdSql);
		StringBuffer sb = new StringBuffer();
		StringBuffer qb = new StringBuffer();
		String queryColumns = "";
		for(int i=0;i<disnamearray.length;i++){
			String columnCnNameSql = "select cn_name from auto_forms_field t where t.field_name = '"+disnamearray[i]+"' and t.forms_id = '"+tableList.get(0).toString()+"'";
			List disCnNameList = autoFormService.getDatabySql(columnCnNameSql);
			disnameshow += "{name:'"+disnamearray[i]+"',index:'"+disnamearray[i]+"', width:200},";
			disnameshow1 += ",'"+disnamearray[i]+"':'\"+row."+disnamearray[i]+"+\"'";
			headershow += ",'"+disCnNameList.get(0)+"'";
			/********************************************查询条件生成  START*************************************/
			
			qb.append("\""+disnamearray[i]+"\":encodeURIComponent(jQuery('#"+disnamearray[i]+"').val()),");
			queryColumns += disnamearray[i]+",";
			sb.append(disCnNameList.get(0)+"：<input type=\"text\" class=\"input\" style=\"width:150px;\" id=\""+disnamearray[i]+"\" name=\""+disnamearray[i]+"\" value=\"\" />");
			
		}
		disnameshow1+="}";
		getRequest().setAttribute("queryValue", qb);
		getRequest().setAttribute("queryColumns", queryColumns);
		getRequest().setAttribute("queryContent", sb);
		
		/****************************************查询条件生成  END****************************************/
		this.getRequest().setAttribute("media", media);
		this.getRequest().setAttribute("headershow", headershow);
		this.getRequest().setAttribute("disnameshow", disnameshow);
		this.getRequest().setAttribute("tablename", tablename);
		this.getRequest().setAttribute("colname", colname);
		this.getRequest().setAttribute("disname", disname);
		this.getRequest().setAttribute("cnname", cnname);
		this.getRequest().setAttribute("fileColname", fileColname);
		this.getRequest().setAttribute("disnameshow1", disnameshow1);
		this.getRequest().setAttribute("flowid", flowid);
		this.getRequest().setAttribute("formid", formid);
		this.getRequest().setAttribute("fileName", fileName);
		this.getRequest().setAttribute("byTableValueId", byTableValueId);
		this.getRequest().setAttribute("unittype", unittype);
		//this.getRequest().setAttribute("columns", columns);
		return "chooseDatalistpage";
	}
	
	/**
	 * 下载文件
	 * @throws Exception
	 */
	public void getFileDownload() throws Exception{
		String url = getRequest().getSession().getAttribute("SYS_FILEPATH").toString();
		String path = new String(getRequest().getParameter("filePath").getBytes("ISO-8859-1"));
		path = url+"/"+StringUtil.encodingUrl(path);
		if(!"".equals(path)){
			File file=new File(path);//构造要下载的文件	
			if(file.exists()){
				InputStream ins=new FileInputStream(path);//构造一个读取文件的IO流对象
				BufferedInputStream bins=new BufferedInputStream(ins);//放到缓冲流里面
				OutputStream outs=getResponse().getOutputStream();//获取文件输出IO流
				BufferedOutputStream bouts=new BufferedOutputStream(outs);
				getResponse().setContentType("application/x-download");//设置response内容的类型
				getResponse().setHeader("Content-disposition","attachment;filename="+ URLEncoder.encode(path, "UTF-8"));//设置头部信息
				int bytesRead = 0;
				byte[] buffer = new byte[8192];
				//开始向网络传输文件流
				while ((bytesRead = bins.read(buffer, 0, 8192)) != -1) {
					bouts.write(buffer, 0, bytesRead);
				}
				bouts.flush();//这里一定要调用flush()方法
				ins.close();
				bins.close();
				outs.close();
				bouts.close();
			}else{
				System.out.println("下载的文件不存在");
			}
		}else{
			System.out.println("下载文件时参数错误");
		}

	}
	/**
	 * 
	 * 描述：判断唯一性
	 * @author wangxd
	 * @date Aug 27, 2015 3:20:44 PM
	 * @return void
	 * @throws IOException 
	 * @throw
	 */
	public void checkMessageWeiyi() throws IOException{
		PrintWriter out = getResponse().getWriter();
		String tableName = getRequest().getParameter("tableName");
		String flowtaskid = getRequest().getParameter("flowtaskid");
		String columName = getRequest().getParameter("columName");
		String valueMsg = getRequest().getParameter("valueMsg");
		if(!StringUtil.isEmpty(valueMsg)){
			valueMsg = StringUtil.encodingUrl(valueMsg);
		}
		String flag = "false";
		try {
			//常规检测流程 GWM_SAMPLE:添加样品时验证样品名称和批次号是否重复 
			if(null!=valueMsg && !"".equals(valueMsg)){
				if("GWM_SAMPLE".equals(tableName)){
					String sql = "select t.id  from "+tableName +" t where t_taskid = "+flowtaskid+" and "+valueMsg;
					List list = autoFormService.getDatabySql(sql);
					if(null!=list&&list.size()>0&&null!=list.get(0)){
						flag = "true";
					}
				}else{
					String sql = "select t.id from "+tableName +"  where  "+valueMsg;
					List list = autoFormService.getDatabySql(sql);
					if(null!=list&&list.size()>0&&null!=list.get(0)){
						flag = "true";
					}
				}
			}else{
				if("GWM_SAMPLE".equals(tableName)){
					String sql = "select count(*) from "+tableName +" where t_taskid = "+flowtaskid+" and "+columName+" is null ";
					List list = autoFormService.getDatabySql(sql);
					if(null!=list&&list.size()>0&&null!=list.get(0)){
						if(!"0".equals(list.get(0).toString())){
							flag = "true";
						}
					}
				}
			}
			out.print("{\"result\":\""+flag+"\"}");
			
		} catch (Exception e) {
			out.print("{\"result\":\"error\"}");
			e.printStackTrace();
		}
	}
	
	/**
	 * 
	 * 描述：检测项目管理 添加检测项目
	 * @author wangxd
	 * @date Sep 24, 2015 9:37:32 AM
	 * @return void
	 * @throws IOException 
	 * @throw
	 */
	public void saveGwmItem() throws IOException{
		PrintWriter out = getResponse().getWriter();
		try {
			String itemName =  getRequest().getParameter("T_ITEMNAME");     //检测项目
			String danwei = getRequest().getParameter("T_JIANCEDANWEI");    //检测单位
			String danweiName = getRequest().getParameter("T_JIANCEDANWEI_NAME");//检测单位名称
			String gongsidaima = getRequest().getParameter("T_GONGSIDAIMA");//检测单位代码
			String didian = getRequest().getParameter("T_JIANCEDIDIAN");    //检测地点
			String bumen = getRequest().getParameter("T_JIANCEBUMEN");      //检测部门
			String leibie = getRequest().getParameter("T_JIACELEIBIE");      //检测类别
			String feiyong = getRequest().getParameter("T_JIANCEMONEY");    //检测费用
			String biaozhun = getRequest().getParameter("T_JIACEBIAOZHUN"); //检测标准
			String canshu =  getRequest().getParameter("T_JIANCECANSHU");   //检测参数
			String bumenId = "''"; //检测部门ID
			if(!"".equals(bumen)){
				String queryDept = "select t.org_id from sys_organization t where t.org_name='"+bumen+"'";
				List list = autoFormService.getDatabySql(queryDept);
				if(null!=list&list.size()>0&&null!=list.get(0)){
					bumenId = list.get(0).toString();
				}
			}
			String insertSql = "insert into gwm_item " +
					           "(id, t_jiancebumen, t_gongsidaima, t_jiancedidian, t_jiaceleibie, t_itemname, t_jiancedanwei, t_jiancemoney, t_jiancecanshu, t_jiancebiaozhun, t_jiancebumen_id, t_jiancedanwei_name) values  " +
					           "(SEQ_GWM_ITEM.NEXTVAL,'"+bumen+"','"+gongsidaima+"','"+didian+"','"+leibie+"','"+itemName+"','"+danwei+"','"+feiyong+"','"+canshu+"','"+biaozhun+"',"+bumenId+",'"+danweiName+"')";
			autoFormService.executeSql(insertSql);
			
			
			out.print("{\"result\":\"success\"}");
		} catch (Exception e) {
			e.printStackTrace();
			out.print("{\"result\":\"error\"}");
		}
	}
	
	public void getForminfoBymodeid() throws IOException{
		PrintWriter out = getResponse().getWriter();
		try {
			String modeid = getRequest().getParameter("modeid");
			String strSql = "select baseinfoid,datainfoid from file_mode t where t.id='"+modeid+"'";
			List lists = autoFormService.findAllBySql(strSql);
			Object[] objs = (Object[])lists.get(0);
			String forminfo = "{\"baseinfoid\":\""+(objs[0]==null?"":objs[0].toString())+"\",\"datainfoid\":\""+(objs[1]==null?"":objs[1].toString())+"\"}";
			out.print(forminfo);
		}
		catch(Exception exp){
			exp.printStackTrace();
		}
		
	}
	
	/**
	 * 
	 * 描述：检测项目管理 修改检测项目、检测标准
	 * @author wangxd
	 * @date Sep 24, 2015 9:37:32 AM
	 * @return void
	 * @throws IOException 
	 * @throw
	 */
	public void updateGwmItemAndBiaozhun() throws IOException{
		PrintWriter out = getResponse().getWriter();
		try {
			
			String itemName =  getRequest().getParameter("T_ITEMNAME");     //检测项目
			String danwei = getRequest().getParameter("T_JIANCEDANWEI");    //检测单位
			String danweiName = getRequest().getParameter("T_JIANCEDANWEI_NAME");//检测单位名称
			String gongsidaima = getRequest().getParameter("T_GONGSIDAIMA");//检测单位代码
			String didian = getRequest().getParameter("T_JIANCEDIDIAN");    //检测地点
			String bumen = getRequest().getParameter("T_JIANCEBUMEN");      //检测部门
			String leibie = getRequest().getParameter("T_JIACELEIBIE");      //检测类别
			String feiyong = getRequest().getParameter("T_JIANCEMONEY");    //检测费用
			String biaozhun = getRequest().getParameter("T_JIACEBIAOZHUN"); //检测标准
			String canshu =  getRequest().getParameter("T_JIANCECANSHU");   //检测参数
			String flag =  getRequest().getParameter("flag");               //0：修改检测项目  1：修改检测标准
			
			
			String olditemname =  getRequest().getParameter("olditemname");   //原检测项目
			String olddanwei =  getRequest().getParameter("olddanweiId");   //原检测单位Id
			String oldbiaozhun =  getRequest().getParameter("oldbiaozhun");   //原检测标准
			String oldbumen =  getRequest().getParameter("oldbumen");   //原检测部门
			String oldleibie =  getRequest().getParameter("oldleibie");   //原检测类别
			
			
			String bumenId = "''"; //检测部门ID
			if(!"".equals(bumen)){
				String queryDept = "select t.org_id from sys_organization t where t.org_name='"+bumen+"'";
				List list = autoFormService.getDatabySql(queryDept);
				if(null!=list&list.size()>0&&null!=list.get(0)){
					bumenId = list.get(0).toString();
				}
			}
			String updateSql = "update gwm_item " ;
					          
			if("0".equals(flag)){
				updateSql += " set  t_jiancebumen = '"+bumen+"'," +
				             " t_gongsidaima = '"+gongsidaima+"', " +
				             " t_jiancedidian = '"+didian+"'," +
					         " t_jiaceleibie = '"+leibie+"'," +
					         " t_itemname = '"+itemName+"'," +
					         " t_jiancedanwei = '"+danwei+"'," +
					         " t_jiancebumen_id = "+bumenId+"," +
				             " t_jiancedanwei_name = '"+danweiName+"' ";
			}else{
				updateSql += " set t_jiancebiaozhun = '"+biaozhun+"', t_jiancemoney = '"+feiyong+"'";
			}
			updateSql += " where t_itemname='"+olditemname+"' and t_jiancedanwei='"+olddanwei+"' and t_jiancebumen='"+oldbumen+"' and t_jiaceleibie='"+oldleibie+"'";
			if("1".equals(flag)){
				updateSql += " and t_jiancebiaozhun='"+oldbiaozhun+"'";
			}
			autoFormService.executeSql(updateSql);
			
			
			out.print("{\"result\":\"success\"}");
		} catch (Exception e) {
			e.printStackTrace();
			out.print("{\"result\":\"error\"}");
		}
	}
	
	public void createReport(){
		String taskid = getRequest().getParameter("taskid");
		String pathUrl = getRequest().getSession().getServletContext().getRealPath("");
		String path = pathUrl+"/reportfile/reportmode.doc";
		String targetPath = pathUrl+"/reportfile/temp/"+GenerateSequenceUtil.generateSequenceNo()+".doc";
		String taskno = "";
		try {
			copyFile(new File(path), new File(targetPath));
			WordTool wt = new WordTool(targetPath);
			ReportParameter paramter = new ReportParameter();
			taskno = SetTable1Value(wt,taskid);
			paramter.setTaskno(taskno);
			SetTable2Value(wt,paramter);
			SetTable3Value(wt,paramter);
			SetTable4Value(wt,paramter);
			SetTable5Value(wt,paramter);
			SetTable6Value(wt,paramter);
			SetTable9Value(wt,paramter);
			SetTable10Value(wt,paramter);
			wt.Save();
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		
		File file=new File(targetPath);//构造要下载的文件	
		if(file.exists()){
			InputStream ins;
			try {
				ins = new FileInputStream(targetPath);
				BufferedInputStream bins=new BufferedInputStream(ins);//放到缓冲流里面
				OutputStream outs=getResponse().getOutputStream();//获取文件输出IO流
				BufferedOutputStream bouts=new BufferedOutputStream(outs);
				getResponse().setContentType("application/x-download");//设置response内容的类型
				getResponse().setHeader("Content-disposition","attachment;filename="+ URLEncoder.encode("全面检查报告"+PubMethod.GetTimerName()+".doc", "UTF-8"));//设置头部信息
				int bytesRead = 0;
				byte[] buffer = new byte[8192];
				//开始向网络传输文件流
				while ((bytesRead = bins.read(buffer, 0, 8192)) != -1) {
					bouts.write(buffer, 0, bytesRead);
				}
				bouts.flush();//这里一定要调用flush()方法
				ins.close();
				bins.close();
				outs.close();
				bouts.close();
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
		}else{
			System.out.println("下载的文件不存在");
		}
	}
	
	public String SetTable1Value(WordTool wt,String taskid){
		//任务信息
		String strSql = "select taskno,PIPETYPE,PIPENAME,PIPELINENO,PIPESECTIONNO,TESTTYPE,TESTDATE from PTEM_TEST_TASK t where id='"+taskid+"'";
		List table1list = autoService.getDatabySql(strSql);
		Object[] table1objs = (Object[])table1list.get(0);
		String pipesectionno="";
		if(table1objs[4]!=null)
		{
			pipesectionno=table1objs[4].toString();		
		}
		//使用单位
		wt.SetTableText(1, 2, 3, table1objs[1]==null?"":table1objs[1].toString());
		//设备名称
		wt.SetTableText(1, 3, 3, table1objs[2]==null?"":table1objs[2].toString());
		wt.SetTableText(3, 5, 2, table1objs[2]==null?"":table1objs[2].toString());
		for(int i=5;i<=34;i++){
			wt.SetTableText(i, 1, 2, table1objs[2]==null?"":table1objs[2].toString());
		}
		//压力管道代码
		wt.SetTableText(1, 5, 3, table1objs[3]==null?"":table1objs[3].toString()+
				pipesectionno);
		wt.SetTableText(3, 4, 4, table1objs[3]==null?"":table1objs[3].toString()+
				pipesectionno);
		//检验类别
		wt.SetTableText(1, 6, 3, table1objs[5]==null?"":table1objs[5].toString());
		//检验日期1
		wt.SetBookMarkValue("检验日期1", PubMethod.getFormatString(table1objs[6]));
		
		String taskno = table1objs[0].toString();
		return taskno;
	}
	
	public void SetTable2Value(WordTool wt,ReportParameter parameter){
		String strSql = "select REPORTNO,USEUNIT,REGISTRATIONNO,APPROVEDATE,UNITADDRESS," +
				"SAFETYMANAGER,TELEPHONE,POSTCODE,AERATEDATE,PIPELENGTH," +
				"PIPESTANDARD,DESIGNPRESSURE,DESIGNTEMPRATURE,DESIGNMEDIA,PIPEMATERIAL," +
				"OPERATEPRESSURE,OPERATETEMPERATURE,MAINBASIS,PROBLEMADVISE,TESTCONCLUSION," +
				"PARAMPRESSURE,PARAMTEMPERATURE,PARAMMEDIA,PARAMOTHER,NEXTTESTDATE," +
				"TESTER,CREATEDATE,VERIFYDATE,APPROVEDATE,APPROVENUMBER" +
				" from PTEM_TEST_SUMMARY where TASKNO='"+parameter.getTaskno()+"'";
		List table2list = autoService.getDatabySql(strSql);
		if (table2list.size()>0){
			Object[] table2objs = (Object[])table2list.get(0);
			wt.SetBookMarkValue("报告编号", table2objs[0]==null?"":table2objs[0].toString());
			parameter.setReportno(table2objs[0].toString());
			//使用单位
			wt.SetTableText(1, 1, 3, table2objs[1]==null?"":table2objs[1].toString());
			wt.SetTableText(3, 1, 2, table2objs[1]==null?"":table2objs[1].toString());
			wt.SetTableText(3, 2, 2, table2objs[1]==null?"":table2objs[1].toString());
			//使用登记证号
			wt.SetTableText(1, 4, 3, table2objs[2]==null?"":table2objs[2].toString());
			wt.SetTableText(3, 6, 2, table2objs[2]==null?"":table2objs[2].toString());
			//检验日期2
			wt.SetBookMarkValue("检验日期2", PubMethod.getFormatString(table2objs[3]));
			//单位地址
			wt.SetTableText(3, 1, 2, table2objs[4]==null?"":table2objs[4].toString());
			//安全管理人员
			wt.SetTableText(3, 3, 2, table2objs[5]==null?"":table2objs[5].toString());
			//联系电话
			wt.SetTableText(3, 3, 4, table2objs[6]==null?"":table2objs[6].toString());
			//邮政编码
			wt.SetTableText(3, 4, 2, table2objs[7]==null?"":table2objs[7].toString());
			//投用日期
			wt.SetTableText(3, 6, 4, PubMethod.getFormatString(table2objs[8]));
			//管道长度
			wt.SetTableText(3, 7, 3, table2objs[9]==null?"":table2objs[9].toString());
			//管道规格
			wt.SetTableText(3, 7, 5, table2objs[10]==null?"":table2objs[10].toString());
			//设计压力
			wt.SetTableText(3, 8, 3, table2objs[11]==null?"":table2objs[11].toString());
			//设计温度
			wt.SetTableText(3, 8, 5, table2objs[12]==null?"":table2objs[12].toString());
			//设计介质
			wt.SetTableText(3, 9, 3, table2objs[13]==null?"":table2objs[13].toString());
			//管道材质
			wt.SetTableText(3, 9, 5, table2objs[14]==null?"":table2objs[14].toString());
			//操作压力
			wt.SetTableText(3, 10, 3, table2objs[15]==null?"":table2objs[15].toString());
			//操作温度
			wt.SetTableText(3, 10, 5, table2objs[16]==null?"":table2objs[16].toString());
			//主要依据
			wt.SetTableText(3, 11, 2, table2objs[17]==null?"":table2objs[17].toString());
			//问题及处理意见
			wt.SetTableText(3, 12, 2, table2objs[18]==null?"":table2objs[18].toString());
			//检验结论
			wt.SetTableText(3, 13, 2, table2objs[19]==null?"":table2objs[19].toString());
			//许用参数
			wt.SetBookMarkValue("许用参数压力", table2objs[20]==null?"":table2objs[20].toString());
			wt.SetBookMarkValue("许用参数温度", table2objs[21]==null?"":table2objs[21].toString());
			wt.SetBookMarkValue("许用参数介质", table2objs[22]==null?"":table2objs[22].toString());
			wt.SetBookMarkValue("许用参数其他", table2objs[23]==null?"":table2objs[23].toString());
			//下次全面检验日期
			wt.SetBookMarkValue("下次全面检验日期", PubMethod.getFormatString(table2objs[24]));
			//检验人员
			wt.SetBookMarkValue("检验人员", table2objs[25]==null?"":table2objs[25].toString());
			//编制日期
			wt.SetBookMarkValue("编制日期", PubMethod.getFormatString(table2objs[26]));
			//审核日期
			String shenherq = PubMethod.getFormatString(table2objs[27]);
			wt.SetBookMarkValue("审核日期", shenherq);
			//批准日期
			wt.SetBookMarkValue("批准日期1", PubMethod.getFormatString(table2objs[28]));
			wt.SetBookMarkValue("批准日期2", PubMethod.getFormatString(table2objs[28]));
			wt.SetBookMarkValue("批准日期3", PubMethod.getFormatString(table2objs[28]));
			//检验机构核准证号
			wt.SetBookMarkValue("检验机构核准证号", table2objs[29]==null?"":table2objs[29].toString());
		}
	}
	
	public void SetTable3Value(WordTool wt,ReportParameter parameter){
		String strSql = "select PIPELINENO,PIPELINELENGTH,PROJECTNAME,PIPESTANDARD,PIPELEVEL," +
				"PIPEMATERIAL,DESIGNUNIT,DESIGNSTANDARD,BUILDER,BUILDSTANDARD," +
				"CORROSIONPROTECTIONUNIT,CORROSIONPROTECTIONSTANNDARD,CORROSIONPROTECTIOMODE,CPTYPE,CALCULATIONSHEET," +
				"CERTIFICATION,CREDENTIALS,REGISTRATION,RUNRECORD,TESTREPORT," +
				"LASTREPORT,OTHERMATERIAL,PROBLEMRECORD,LASTTESTRECORD from  PTEM_MATERIALS_REVIEW where TASKNO='"+parameter.getTaskno()+"'";
		List table3list = autoService.getDatabySql(strSql);
		if (table3list.size()>0){
			Object[] table3objs = (Object[])table3list.get(0);
			//管线编号
			wt.SetTableText(4, 1, 2, table3objs[0]==null?"":table3objs[0].toString());
			//管段长度
			wt.SetTableText(4, 1, 4, table3objs[1]==null?"":table3objs[1].toString());
			//工程名称
			wt.SetTableText(4, 2, 2, table3objs[2]==null?"":table3objs[2].toString());
			String projecname = table3objs[0]==null?"":table3objs[2].toString();
			strSql = "select  SUPERVISORUNIT,COMPLETIONDATE,PAVEMODE,AERATEDATE from PTEM_PROJECT_INFO " +
					"where PROJECTNAME='"+projecname+"'";
			List tablealist = autoService.getDatabySql(strSql);
			if (tablealist.size()>0){
				Object[] tableaobjs = (Object[])tablealist.get(0);
				//监理单位
				wt.SetTableText(4, 7, 2, tableaobjs[0]==null?"":tableaobjs[0].toString());
				//竣工日期
				wt.SetTableText(4, 7, 4, PubMethod.getFormatString(tableaobjs[1]));
				//铺设方式
				wt.SetTableText(4, 8, 2, tableaobjs[2]==null?"":tableaobjs[2].toString());
				//投用日期
				wt.SetTableText(4, 8, 4, PubMethod.getFormatString(tableaobjs[3]));
			}
			//管道规格
			wt.SetTableText(4, 2, 4, table3objs[3]==null?"":table3objs[3].toString());
			//管道级别
			wt.SetTableText(4, 3, 2, table3objs[4]==null?"":table3objs[4].toString());
			//管道材质
			wt.SetTableText(4, 3, 4, table3objs[5]==null?"":table3objs[5].toString());
			//设计单位
			wt.SetTableText(4, 4, 2, table3objs[6]==null?"":table3objs[6].toString());
			//设计规范
			wt.SetTableText(4, 4, 4, table3objs[7]==null?"":table3objs[7].toString());
			//施工单位
			wt.SetTableText(4, 5, 2, table3objs[8]==null?"":table3objs[8].toString());
			//施工规范
			wt.SetTableText(4, 5, 4, table3objs[9]==null?"":table3objs[9].toString());
			//防腐单位
			wt.SetTableText(4, 6, 2, table3objs[10]==null?"":table3objs[10].toString());
			//防腐规范
			wt.SetTableText(4, 6, 4, table3objs[11]==null?"":table3objs[11].toString());
			//防腐方式
			wt.SetTableText(4, 9, 2, table3objs[12]==null?"":table3objs[12].toString());
			//阴极保护方式
			wt.SetTableText(4, 9, 4, table3objs[13]==null?"":table3objs[13].toString());
			//设计图纸、文件与有关强度计算书
			wt.SetTableText(4, 11, 3, table3objs[14]==null?"":table3objs[14].toString());
			//管道元件产品质量证明资料
			wt.SetTableText(4, 12, 3, table3objs[15]==null?"":table3objs[15].toString());
			//安装监督检验证明文件、安装及竣工验收资料
			wt.SetTableText(4, 13, 3, table3objs[16]==null?"":table3objs[16].toString());
			//管道使用登记证
			wt.SetTableText(4, 14, 3, table3objs[17]==null?"":table3objs[17].toString());
			//管道运行记录
			wt.SetTableText(4, 15, 3, table3objs[18]==null?"":table3objs[18].toString());
			//运行周期内的年度检查报告
			wt.SetTableText(4, 16, 3, table3objs[19]==null?"":table3objs[19].toString());
			//上一次全面检验报告
			wt.SetTableText(4, 17, 3, table3objs[20]==null?"":table3objs[20].toString());
			//检验人员认为全面检验所需要的其他资料
			wt.SetTableText(4, 18, 3, table3objs[21]==null?"":table3objs[21].toString());
			//资料审查问题记载
			wt.SetTableText(4, 19, 2, table3objs[22]==null?"":table3objs[22].toString());
			//上次定期检验问题记载
			wt.SetTableText(4, 20, 2, table3objs[23]==null?"":table3objs[23].toString());
		}
	}
	
	/**
	 * 宏观检查报告
	 * @param wt
	 * @param taskno
	 */
	public void SetTable4Value(WordTool wt,ReportParameter parameter){
		String strSql = "select PIPELOCATION,PIPETREND,PIPEDEPTH,GROUNDMARKCHECK,DISTANCE," +
				"OCCUPYSTATUS,ISEXPOSED,ISDESTROY,HIGHCONSEQUENCE,ANCHORBLOCK," +
				"CHECKHOLE,ERODESTATUS,COATING,COMPENSATION,FUPPORTPOST," +
				"EROSIONSTATUS,SYPHONBOX,VALVE,FLANGE,COMPENSATOR," +
				"INSULATEDJOINT,OTHER,STATEMENT,TESTER,VERIFIER" +
				" from PTEM_MACRO_TEST t where TASKNO='"+parameter.getTaskno()+"'";
		List table4list = autoService.getDatabySql(strSql);
		if (table4list.size()>0){
			Object[] table4objs = (Object[])table4list.get(0);
			//管道位置
			wt.SetTableText(5, 3, 3, table4objs[0]==null?"":table4objs[0].toString());
			//管道走向
			wt.SetTableText(5, 4, 3, table4objs[1]==null?"":table4objs[1].toString());
			//管道埋深
			wt.SetTableText(5, 5, 3, table4objs[2]==null?"":table4objs[2].toString());
			//地面标志检查
			wt.SetTableText(5, 6, 2, table4objs[3]==null?"":table4objs[3].toString());
			//与建筑物或其他管道净距
			wt.SetTableText(5, 7, 3, table4objs[4]==null?"":table4objs[4].toString());
			//占压状况
			wt.SetTableText(5, 8, 3, table4objs[5]==null?"":table4objs[5].toString());
			//管道裸露情况
			wt.SetTableText(5, 9, 3, table4objs[6]==null?"":table4objs[6].toString());
			//施工破坏
			wt.SetTableText(5, 10, 3, table4objs[7]==null?"":table4objs[7].toString());
			//高后果区情况
			wt.SetTableText(5, 11, 3, table4objs[8]==null?"":table4objs[8].toString());
			//锚固墩情况
			wt.SetTableText(5, 12, 4, table4objs[9]==null?"":table4objs[9].toString());
			//套管检查孔
			wt.SetTableText(5, 13, 4, table4objs[10]==null?"":table4objs[10].toString());
			//冲刷侵蚀情况
			wt.SetTableText(5, 14, 4, table4objs[11]==null?"":table4objs[11].toString());
			//防腐层
			wt.SetTableText(5, 15, 4, table4objs[12]==null?"":table4objs[12].toString());
			//补偿情况
			wt.SetTableText(5, 16, 4, table4objs[13]==null?"":table4objs[13].toString());
			//支吊架
			wt.SetTableText(5, 17, 4, table4objs[14]==null?"":table4objs[14].toString());
			//腐蚀情况
			wt.SetTableText(5, 18, 4, table4objs[15]==null?"":table4objs[15].toString());
			//凝水缸
			wt.SetTableText(5, 19, 2, table4objs[16]==null?"":table4objs[16].toString());
			//阀门
			wt.SetTableText(5, 20, 3, table4objs[17]==null?"":table4objs[17].toString());
			//法兰
			wt.SetTableText(5, 21, 3, table4objs[18]==null?"":table4objs[18].toString());
			//补偿器
			wt.SetTableText(5, 22, 3, table4objs[19]==null?"":table4objs[19].toString());
			//绝缘接头
			wt.SetTableText(5, 23, 3, table4objs[20]==null?"":table4objs[20].toString());
			//其它
			wt.SetTableText(5, 24, 2, table4objs[21]==null?"":table4objs[21].toString());
			//说明
			wt.SetTableText(5, 25, 2, table4objs[22]==null?"":table4objs[22].toString());
		}
	}
	
	/**
	 * 泄漏检查报告
	 * @param wt
	 * @param taskno
	 */
	public void SetTable5Value(WordTool wt,ReportParameter parameter){
		String strSql = "select EXCUTESTARDARD,DEVICEMODEL,DEVICENO,SENSITIVITY from PTEM_LEAK_TEST t where TASKNO='"+parameter.getTaskno()+"'";
		List tablelist = autoService.getDatabySql(strSql);
		if (tablelist.size()>0){
			Object[] tableobjs = (Object[])tablelist.get(0);
			//管道位置
			wt.SetTableText(6, 2, 2, tableobjs[0]==null?"":tableobjs[0].toString());
		}
		wt.InsertRows(6, 5, tablelist.size()-1);
		for(int i=0;i<tablelist.size();i++){
			Object[] tableobjs = (Object[])tablelist.get(i);
			wt.SetTableText(6, 5+i, 1, tableobjs[1]==null?"":tableobjs[1].toString());
			wt.SetTableText(6, 5+i, 2, tableobjs[2]==null?"":tableobjs[2].toString());
			wt.SetTableText(6, 5+i, 3, tableobjs[3]==null?"":tableobjs[3].toString());
		}
	}
		/**
		 * 敷设环境调查报告——土壤电阻率
		 * @param wt
		 * @param taskno
		 */
		public void SetTable6Value(WordTool wt,ReportParameter parameter){
			String strSql = "select DEVICENAMEMODEL,DEVICENO,TESTMETHOD,EXCUTESTANDARD,PIPELINENO,LOCATIONY,LOCATIONX,PIPEDEPTH,POLEDISTANCE,SHOWVALUE," +
					"SOILRESISTIVITY,SOILCORROSIONEVALUATE from  PTEM_SOILCORROSION t where TASKNO='"+parameter.getTaskno()+"'";
			List tablelist = autoService.getDatabySql(strSql);
			if (tablelist.size()>0){
				Object[] tableobjs = (Object[])tablelist.get(0);
				//设备名称及型号
				wt.SetTableText(7, 2, 2, tableobjs[0]==null?"":tableobjs[0].toString());
				//设备编号
				wt.SetTableText(7, 2, 4, tableobjs[1]==null?"":tableobjs[0].toString());
				//检测方法
				wt.SetTableText(7, 2, 6, tableobjs[2]==null?"":tableobjs[0].toString());
				//检测标准
				wt.SetTableText(7, 3, 2, tableobjs[3]==null?"":tableobjs[0].toString());
					
			}
			wt.InsertRows(7, 6, tablelist.size()-1);
			for(int i=0;i<tablelist.size();i++){
				Object[] tableobjs = (Object[])tablelist.get(i);
				//序号
				wt.SetTableText(7, 6+i, 1, Integer.toString(i+1) );
				//管线编号
				wt.SetTableText(7, 6+i, 2, tableobjs[1]==null?"":tableobjs[4].toString());
				//经度
				wt.SetTableText(7, 6+i, 3, tableobjs[2]==null?"":tableobjs[5].toString());
				//纬度
				wt.SetTableText(7, 6+i, 4, tableobjs[3]==null?"":tableobjs[6].toString());
				//管道埋深
				wt.SetTableText(7, 6+i, 5, tableobjs[1]==null?"":tableobjs[7].toString());
				//电极间距
				wt.SetTableText(7, 6+i, 6, tableobjs[2]==null?"":tableobjs[8].toString());
				//仪器显示值
				wt.SetTableText(7, 6+i, 7, tableobjs[3]==null?"":tableobjs[9].toString());
				//土壤电阻率
				wt.SetTableText(7, 6+i, 8, tableobjs[1]==null?"":tableobjs[10].toString());
				//土壤腐蚀性
				wt.SetTableText(7, 6+i, 9, tableobjs[2]==null?"":tableobjs[11].toString());
			}
	}
		/**
		 * 敷设环境调查报告——土壤腐蚀性
		 * @param wt
		 * @param taskno
		 */
		public void SetTable7Value(WordTool wt,ReportParameter parameter){
			String strSql = "select EXCUTESTANDARD,TESTPOINTDESCRIPTION,LOCATIONY,LOCATIONX,SOILRESISTIVITY,SOILTEXTURE,CORROSIONPOTENTIAL," +
					"REDOXPOTENTIAL,PHVALUE,MOISTURECONTENT,SALTCONTENT,C1CONTENT,SOILCORROSIONLEVEL from  PTEM_SOILCORROSION t where TASKNO='"+parameter.getTaskno()+"'";
			List tablelist = autoService.getDatabySql(strSql);
//			if (tablelist.size()>0){
//				Object[] tableobjs = (Object[])tablelist.get(0);
//				//设备名称及型号
//				wt.SetTableText(7, 2, 2, tableobjs[0]==null?"":tableobjs[0].toString());
//				//设备编号
//				wt.SetTableText(7, 2, 4, tableobjs[1]==null?"":tableobjs[0].toString());
//				//检测方法
//				wt.SetTableText(7, 2, 6, tableobjs[2]==null?"":tableobjs[0].toString());
//				//检测标准
//				wt.SetTableText(7, 3, 2, tableobjs[3]==null?"":tableobjs[0].toString());
//					
//			}
//			wt.InsertRows(7, 6, tablelist.size()-1);
//			for(int i=0;i<tablelist.size();i++){
//				Object[] tableobjs = (Object[])tablelist.get(i);
//				//序号
//				wt.SetTableText(7, 6+i, 1, Integer.toString(i+1) );
//				//管线编号
//				wt.SetTableText(7, 6+i, 2, tableobjs[1]==null?"":tableobjs[4].toString());
//				//经度
//				wt.SetTableText(7, 6+i, 3, tableobjs[2]==null?"":tableobjs[5].toString());
//				//纬度
//				wt.SetTableText(7, 6+i, 4, tableobjs[3]==null?"":tableobjs[6].toString());
//				//管道埋深
//				wt.SetTableText(7, 6+i, 5, tableobjs[1]==null?"":tableobjs[7].toString());
//				//电极间距
//				wt.SetTableText(7, 6+i, 6, tableobjs[2]==null?"":tableobjs[8].toString());
//				//仪器显示值
//				wt.SetTableText(7, 6+i, 7, tableobjs[3]==null?"":tableobjs[9].toString());
//				//土壤电阻率
//				wt.SetTableText(7, 6+i, 8, tableobjs[1]==null?"":tableobjs[10].toString());
//				//土壤腐蚀性
//				wt.SetTableText(7, 6+i, 9, tableobjs[2]==null?"":tableobjs[11].toString());
//			}
}
			
			/**
			 * 敷设环境调查报告——杂散电流（汇总）
			 * @param wt
			 * @param taskno
			 */
			public void SetTable8Value(WordTool wt,ReportParameter parameter){
				String strSql = "select PIPELINENO,STRAYPOINTDESCRIPTION,POTENTIALGRADIENT,EVALUATIONLEVEL from  PTEM_SOILCORROSION t where TASKNO='"+parameter.getTaskno()+"'";
				List tablelist = autoService.getDatabySql(strSql);
				
			
		}
			
			/**
			 * 敷设环境调查报告——杂散电流
			 * @param wt
			 * @param taskno
			 */
			public void SetTable9Value(WordTool wt,ReportParameter parameter){
				String strSql = "select COATINGTYPE,CPWAY,PIPELINENO,LOCATIONY,LOCATIONX,STRAYPOINTDESCRIPTION,GROUNDSTATUS,DEVICENAMEMODEL,DEVICENO," +
						"TESTMETHOD,REFERENCETYPE,EXCUTESTANDARD, EVALUATIONLEVEL from  PTEM_STRAYCURRENTTEST t where TASKNO='"+parameter.getTaskno()+"'";
				List tablelist = autoService.getDatabySql(strSql);
				if (tablelist.size()>0){
					Object[] tableobjs = (Object[])tablelist.get(0);
					//防腐层类型
					wt.SetTableText(10, 2, 2, tableobjs[0]==null?"":tableobjs[0].toString());
					//阴极保护方式
					wt.SetTableText(10, 2, 4, tableobjs[1]==null?"":tableobjs[1].toString());
					//管线编号
					wt.SetTableText(10, 3, 2, tableobjs[2]==null?"":tableobjs[2].toString());
					//坐标Y
					wt.SetTableText(10, 3, 4, tableobjs[3]==null?"":tableobjs[3].toString());
					//坐标X
					wt.SetTableText(10, 3, 6, tableobjs[4]==null?"":tableobjs[4].toString());
					//杂散检测点描述
					wt.SetTableText(10, 4, 2, tableobjs[5]==null?"":tableobjs[5].toString());
					//地表情况
					wt.SetTableText(10, 4, 4, tableobjs[6]==null?"":tableobjs[6].toString());
					//设备名称及型号
					wt.SetTableText(10, 5, 2, tableobjs[7]==null?"":tableobjs[7].toString());	
					//设备编号
					wt.SetTableText(10, 5, 4, tableobjs[8]==null?"":tableobjs[8].toString());
					//检测方法
					wt.SetTableText(10, 6, 2, tableobjs[9]==null?"":tableobjs[9].toString());
					//参比类型
					wt.SetTableText(10, 6, 4, tableobjs[10]==null?"":tableobjs[10].toString());
					//执行标准 
					wt.SetTableText(10, 7, 2, tableobjs[11]==null?"":tableobjs[11].toString());
					//20XX年公用管道数据光盘/任务编号 报告编号/表52杂散电流检测.xlsx
					wt.SetTableText(10, 8, 2, "20XX年公用管道数据光盘/"+parameter.getReportno()+ "报告编号/表52杂散电流检测.xlsx");
					//评价等级
					wt.SetTableText(10, 10, 1, "检测结果："+(tableobjs[12]==null?"":tableobjs[12].toString()));
				}				
		}
			
			/**
			 * 敷设环境调查报告——绝缘电阻(汇总)
			 * @param wt
			 * @param taskno
			 */
			public void SetTable10Value(WordTool wt,ReportParameter parameter){
				String strSql = "select PIPELINENO,RISOVALUE,RISOVALUELEVEL,REMARK from  PTEM_COATING_RISO_EVALUATE t where TASKNO='"+parameter.getTaskno()+"'";
				List tablelist = autoService.getDatabySql(strSql);
				//防腐层类型
				String COATINGTYPE ="";
				//阴极保护类型
				String CPTYPE="";
				if (tablelist.size()>0)
				{					
					wt.InsertRows(11, 4, tablelist.size()-1);
					for(int i=0;i<tablelist.size();i++){
						Object[] tableobjs = (Object[])tablelist.get(i);
						//序号
						wt.SetTableText(11, 4+i, 1, Integer.toString(i+1) );
						//管线编号
						wt.SetTableText(11, 4+i, 2, tableobjs[0]==null?"":tableobjs[0].toString());
						//平均绝缘电阻值（kΩ*㎡）
						wt.SetTableText(11, 4+i, 4, tableobjs[1]==null?"":tableobjs[1].toString());
						//评定等级
						wt.SetTableText(11, 4+i, 5, tableobjs[2]==null?"":tableobjs[2].toString());
						//备注
						wt.SetTableText(11, 4+i, 6, tableobjs[3]==null?"":tableobjs[3].toString());
						
						//管段描述
						String pipelino = tableobjs[0]==null?"":tableobjs[0].toString();
						String strsql1 = "select PROJECTNAME, COATINGTYPE,CPTYPE from   PTEM_PIPELINE t where PIPELINENO='"+pipelino+"'";
						List tablelist1 = autoService.getDatabySql(strsql1);
						if (tablelist1.size()>0)
						{
							Object[] tableobjs1 = (Object[])tablelist1.get(0);
							wt.SetTableText(11, 4+i, 3,tableobjs1[0]==null?"":tableobjs1[0].toString() );
							COATINGTYPE=tableobjs1[1]==null?"":tableobjs1[1].toString()+","+COATINGTYPE;
							CPTYPE = tableobjs1[2]==null?"":tableobjs1[2].toString()+","+CPTYPE;
						}
				
					}
					//防腐层类型
					wt.SetTableText(11, 2, 2, COATINGTYPE);
					//阴极保护类型
					wt.SetTableText(11, 2, 4, CPTYPE);
				}					
		}	
	
			
			/**
			 * 敷设环境调查报告——绝缘电阻
			 * @param wt
			 * @param taskno
			 */
			public void SetTable11Value(WordTool wt,ReportParameter parameter){
				String strSql = "select PIPELINENO,RISOVALUE,RISOVALUELEVEL,REMARK from  PTEM_COATING_RISO_EVALUATE t where TASKNO='"+parameter.getTaskno()+"'";
				List tablelist = autoService.getDatabySql(strSql);
				//防腐层类型
				String COATINGTYPE ="";
				//阴极保护类型
				String CPTYPE="";
				if (tablelist.size()>0)
				{					
					wt.InsertRows(11, 4, tablelist.size()-1);
					for(int i=0;i<tablelist.size();i++){
						Object[] tableobjs = (Object[])tablelist.get(i);
						//序号
						wt.SetTableText(11, 4+i, 1, Integer.toString(i+1) );
						//管线编号
						wt.SetTableText(11, 4+i, 2, tableobjs[0]==null?"":tableobjs[0].toString());
						//平均绝缘电阻值（kΩ*㎡）
						wt.SetTableText(11, 4+i, 4, tableobjs[1]==null?"":tableobjs[1].toString());
						//评定等级
						wt.SetTableText(11, 4+i, 5, tableobjs[2]==null?"":tableobjs[2].toString());
						//备注
						wt.SetTableText(11, 4+i, 6, tableobjs[3]==null?"":tableobjs[3].toString());
						
						//管段描述
						String strsql = "select PROJECTNAME, COATINGTYPE,CPTYPE from   PTEM_PIPELINE t where PIPELINENO='"+tableobjs[0]==null?"":tableobjs[0].toString()+"'";
						List tablelist1 = autoService.getDatabySql(strSql);
						if (tablelist.size()>0)
						{
							Object[] tableobjs1 = (Object[])tablelist1.get(0);
							wt.SetTableText(11, 4+i, 3,tableobjs1[0]==null?"":tableobjs[0].toString() );
							COATINGTYPE=tableobjs1[1]==null?"":tableobjs[1].toString()+","+COATINGTYPE;
							CPTYPE = tableobjs1[2]==null?"":tableobjs[2].toString()+","+CPTYPE;
						}
				
					}
					//防腐层类型
					wt.SetTableText(11, 2, 2, COATINGTYPE);
					//阴极保护类型
					wt.SetTableText(11, 2, 4, CPTYPE);
				}					
		}	
	public static void copyFile(File sourceFile, File targetFile) throws IOException {
        BufferedInputStream inBuff = null;
        BufferedOutputStream outBuff = null;
        try {
            // 新建文件输入流并对它进行缓冲
            inBuff = new BufferedInputStream(new FileInputStream(sourceFile));

            // 新建文件输出流并对它进行缓冲
            outBuff = new BufferedOutputStream(new FileOutputStream(targetFile));

            // 缓冲数组
            byte[] b = new byte[1024 * 5];
            int len;
            while ((len = inBuff.read(b)) != -1) {
                outBuff.write(b, 0, len);
            }
            // 刷新此缓冲的输出流
            outBuff.flush();
        } finally {
            // 关闭流
            if (inBuff != null)
                inBuff.close();
            if (outBuff != null)
                outBuff.close();
        }
    }
	
	public List getUploadfile() {
		return uploadfile;
	}
	public void setUploadfile(List uploadfile) {
		this.uploadfile = uploadfile;
	}
	public List getUploadfileContentType() {
		return uploadfileContentType;
	}
	public void setUploadfileContentType(List uploadfileContentType) {
		this.uploadfileContentType = uploadfileContentType;
	}
	public List getUploadfileFileName() {
		return uploadfileFileName;
	}
	public void setUploadfileFileName(List uploadfileFileName) {
		this.uploadfileFileName = uploadfileFileName;
	}
	public TdmCustomNo getTdmCustomNo() {
		return tdmCustomNo;
	}
	public void setTdmCustomNo(TdmCustomNo tdmCustomNo) {
		this.tdmCustomNo = tdmCustomNo;
	}
	public static int getMOD_CHECK() {
		return MOD_CHECK;
	}
	
	
}
